Frequency Generator Part 3 - Making the Serial Controls Work (#61)

Поділитися
Вставка
  • Опубліковано 15 вер 2024
  • In #57 and #59 I showed this frequency generator from icstation, which generates good square waves over a wide frequency range.
    The piece I couldn't figure is how to control it via the serial interface. Here I can reveal the secrets.
    Part 1: • Testing a Frequency Ge...
    Part 2: • Testing a Frequency Ge...
    UPDATE: The sample Arduino script I used is now on my github: github.com/mag...

КОМЕНТАРІ • 88

  • @falkodachsel570
    @falkodachsel570 3 роки тому +1

    Thank you so much for this video. It really helped me to solve a serious problem in a production-process.

  • @zorktar
    @zorktar 6 років тому +1

    Thank you for your video. You can use Tera Term if you use the Broadcast command in the Control menu option. this will send the string quickly without delays between the characters. The terminators can be turned off by un-checking the Enter key check box option. Any delay between the characters sent will cause the FAIL response due to a timeout condition. This is why typing the letters one by one replies with FAIL after each letter.

  • @anthonycalia1317
    @anthonycalia1317 6 років тому +1

    Nice Job figuring this out and describing it so well. Keep up the good work

  • @highnumbersface
    @highnumbersface 6 років тому +1

    Well done Martyn. I will try this out with an esp connected to Wi-fi. would be nice to control the thing over mqtt to form something like a led dimmer or an lv fan speed control. Would also be interesting to see how similar control could be done in python on a pi.

  • @georgesawyer8852
    @georgesawyer8852 3 роки тому

    Thanks for the Arduino sketch. My module has 3 outputs with one frequency but 3 different duty cycles. The frequency is set using Fxxxxx. Each duty cycle seems to set with D1:xxx D2:xxx and D3:xxx Hope this helps.

    • @MartynDavies
      @MartynDavies  3 роки тому

      Nice. I don't have a three output one yet, but will most likely get one.

  • @normanharrison1967
    @normanharrison1967 5 років тому +1

    Have solved the pi issue.
    Prompted by somebody else being interested I have had another go.
    Got it working both from Cutecom and a skeleton python program!
    Will tidy up the code tomorrow and post it to the raspberrypi.org forum. I don't think there was a problem with my old code. I was powering the xy-lpwm from the 5v output on the GPIO - although the xy-lpwm display was bright and stable I suspect it was drawing too much from my small pi power supply. Now I have the pi providing power to the tx/rx via a voltage converter (3.3v on pi side, 5v on xy-lpwm side) but a seperate 1amp 5v supply to the VIN+, VIN- on the xy-lpwm.
    Cutecom let's you send to and read the port in a nice clear display.
    I have sent the commands F5.01 D033 etc with no line feed or CR.
    100% success. To read from the xy-lpwm send 'read' in lowercase.
    Your demo helped a lot - wish I had tried the power change earlier! Was banging my head trying to find errors in probably error free code (well at least none that would stop it working).
    Can post link to code here if you want.

  • @MartynDavies
    @MartynDavies  7 місяців тому

    I thought about connecting a few of these to get polyphonic music going... oh well, so many projects; can't get to them all.

  • @ydonl
    @ydonl 6 років тому +1

    I don't have one of these things, nor have I ever played with one, but it does look interesting and useful. I'm looking at these videos primarily as a software engineer.
    I see two potentially signification changes in what you're doing now versus what you were doing originally. One is that you've stopped sending carriage returns (or linefeeds), but the other is that you're buffering the command and sending all of the characters in one continuous block. I suspect it is the latter rather than the former that "fixed" it.
    The reason I don't think the carriage return was the obstacle is that in the original video, the "FAIL" messages were coming on each keystroke -- long before you hit carriage return. You typed "F", and it said "FAIL" because that's not a valid command. You typed "1", and it said "FAIL". Eventually, you hit return, and it of course said "FAIL" again.
    If my theory is correct, and you were to send a carriage return and/or line feed at the end of the command with the current code, it would work -- because the command is sent with no significant delay between characters -- and then it would say "FAIL" because it didn't recognize the line terminator.
    My theory is that the basic reason for this is that the code at the receiving end can be very simple; it does not have to manage a line buffer, assembling the command one character at a time, and then analyze it once it recognizes the full command. Instead, all it has to do is start reading four characters, sequentially and continuously, and then deal with that command. So in the original case, it would read the "F" and then get a timeout -- no serial data available -- and "FAIL". Now it says "read c1, read c2, read c3, read c4", and then evaluates the string that it has assembled.

    • @MartynDavies
      @MartynDavies  6 років тому

      Yes it's clear that sending in a block is the crucial fix. You can can send or not send CR, LF or CR/LF at the end, and it really doesn't care as long as the crucial command was in a continuous stream. But I've worked with a lot of serial devices over the years (even programming the UART/SCC chips myself) and this is the first time that I've seen this. As you suggest, the receiver must have an inter-character timer, or an overall block timer, but it seems to me not any easier to do this as the UART typically only buffers 1 or 2 characters, and sends an interrupt when a character is ready, meaning that the receiving code must deal with the data on a character-by-character basis anyhow, even if the data are en-bloc. Thanks for your comment.

    • @normanharrison1967
      @normanharrison1967 5 років тому

      Having solved my Raspberry Pi issue I have sent control codes without carriage return and/or line feed and it works 100%. With CR &/or LF it fails. However, the data returned from the xy-lpwm does have a CR/LF.

  • @jorgefelipegaviriafierro705
    @jorgefelipegaviriafierro705 3 роки тому

    Thank you

  • @teslasapple
    @teslasapple 6 років тому +1

    Nice work. Thanks for sharing 👍

  • @javierpallalorden
    @javierpallalorden 6 років тому +1

    Excellent, thanks!

  • @titolindj
    @titolindj 2 роки тому +1

    Very good explanation, thanks!
    I wonder if there's a way to change the parameters, so they can only go up to 20 hz and 50% duty?
    Do you think that's possible?

    • @MartynDavies
      @MartynDavies  2 роки тому +1

      I did have a look around a few years ago to see if the code was in the public domain, or derived from some published work, but didn't find anything. It would be good to have an open source version, so that we could create custom code and program our own microcontollers for this module. In short, I think, no, you can't change the way that this module works.

    • @titolindj
      @titolindj 2 роки тому +1

      @@MartynDavies Thank you!
      I was afraid of that...

  • @TechInnovativeBangla
    @TechInnovativeBangla 3 місяці тому +1

    Thank you for this video. Please tell me how to set 100khz to 150 khz frequency with this

    • @MartynDavies
      @MartynDavies  3 місяці тому

      I can't immediately lay my hands on a board at the moment, but 100kHz would be 1.0.0. There's some data on the icstation website: www.icstation.com/signal-generator-pulse-frequency-duty-cycle-adjustable-module-display-150khz-p-12477.html

  • @andymouse
    @andymouse 5 років тому +1

    Cheers!

  • @SoundOfYourDestiny
    @SoundOfYourDestiny 4 роки тому +1

    Thanks for the video. I'm trying to communicate with one of these modules from a Mac, using a Prolific USB-to-serial cable (PL2303TA). I have the terminal settings as described (including no CR/LF, but can't get anything from the module. Sending commands or "read" produces nothing. UPDATE: I had misinterpreted the RX/TX meaning for the USB wires; reversing them fixed the problem.

    • @rickneill6924
      @rickneill6924 3 роки тому +1

      I had the same issue with TXD and RXD. There is at least one image floating around the 'net which shows (using arrows) that TXD is an input and RXD is an output. This is the exact opposite of their function and I had to swap my connections over before it would work. Also, I've interfaced with an old BASIC computer which expects to see LF/CR at the end of received strings (In that exact order - *Not* CR/LF). The module seems to just send LF. In BASIC this the requires the INPUT$ command to be used because INPUT and/or LINE INPUT just hang waiting for a CR which never comes.

    • @SoundOfYourDestiny
      @SoundOfYourDestiny 3 роки тому

      @@rickneill6924 Good work! Also, to anyone else reading this: NEVER use the Prolific driver for Mac. It's hideously defective and can nearly brick your computer. I switched to FTDI chipset and driver.

    • @rickneill6924
      @rickneill6924 3 роки тому

      @@SoundOfYourDestiny Yes, sadly Prolific's chips were illegally cloned and they were/are duds. You can try using old drivers in Windows 10 but eventually I went to FTDI.

  • @jaggi_b
    @jaggi_b Рік тому

    Will the set frequency and duty cycle for both channels individually remain the same even after the power supply is removed? or it gets reset once the power supply is removed.

    • @MartynDavies
      @MartynDavies  Рік тому

      It's a while ago now, but I think it resets when the power goes off.

    • @neilbarnett3046
      @neilbarnett3046 7 місяців тому

      The physically smaller "double" ones (marked HW-0515) claim to have non-volatile settings. I set one this morning and it's still set 10 hours later, power off.

  • @narrderfreiheit
    @narrderfreiheit 3 роки тому

    Hi Martyn,
    thank you for your videos!
    What you show here in Part 3, I was able to understand just as quickly with an Arduino Nano with the same pin numbers. In the next step I wanted to address the XY-LPWM module directly from the program and set a frequency via the serial interface. Unfortunately, I have not yet succeeded in doing this. Martyn, maybe you have a hint or tip for me on how I should proceed or an example would be best. Thank you!

    • @MartynDavies
      @MartynDavies  3 роки тому

      Yes, I would like to do that

    • @narrderfreiheit
      @narrderfreiheit 3 роки тому

      @@MartynDavies That's great! Thank you!

    • @narrderfreiheit
      @narrderfreiheit 3 роки тому +1

      Hi Martyn,
      it works now! I have a test solution that I can use in my small project. If you want, can I send you the sketch?

  • @normanharrison1967
    @normanharrison1967 5 років тому +1

    Hi - thanks for the clear and very useful VIDEOS.
    I am doing a lathe conversation using a treadmill motor with a controller that needs a stable PWM signal. I want to use a Raspberry Pi to provide a touch screen display and need it to send the control signal to the xy-lpwm via GPIO Tx (and get confirmation via Rx). The touch screen bit is straightforward however I am having similar issues with Tx / Rx that you initially experienced. I have linked Tx and Rx on the Pi and confirmed that signals are being sent and read ok. I have linked to the xy-lpwm via a voltage converter. So the pi sees 3.3v and the xy-lpwm 5v. I have tried minimal code to send / receive, the pi terminal and Cutecom terminal all without success. Sending Ctrl C from Cutecom sets the display to 0000 0000. Other than that - nothing. Have you tried using a Raspberry Pi with xy-lpwm or do you have any ideas that might help? Using python3 and Qt for "front-end". Thanks again for your excellent VIDEOS.

    • @MartynDavies
      @MartynDavies  5 років тому

      I haven't tried this unit with the Pi. The serial on this module is weird in that you have to send the command strings as one continuous string and without a terminator (CR, LF or CR/LF), so I imagine off-the-shelf Linux terminal software may fail. I would probably write something in Python using PySerial so that I can customize exactly how the commands are sent. I'll try to set this up if I can find a voltage level shifter.

    • @MartynDavies
      @MartynDavies  5 років тому

      Another approach would be to use an Arduino to generate your PWM signal - you can use analogWrite to generate a PWM proportional to the value you specify. It might be easier to control an Arduino script through serial than this freq module, and you can get 3V compatible modules, e.g. the Arduino Pro Mini which can be obtained very cheaply.

    • @normanharrison1967
      @normanharrison1967 5 років тому

      Thanks for the prompt response. Cutecom let's you send data with and without carriage return or line feed so I hoped that it might at least get me connected. I have tried pi serial - get it working fine linking Tx and Rx as a check. I purchased 10 voltage converters for £5 - maybe that is where the issue is? Happy to post you one for free. But, Ctrl C from Cutecom does have an effect (the 0000 0000 I mentioned) and FAIL does get returned. No magic smoke leaking from either end... Liked the look of this module as it seemed, in theory at least, very easy to set up. I wanted to concentrate on the Pi interface and not complicate it with another device. The treadmill motor controller needs a 5v PWM input. Will look at the arduino alternative if I can't get the xy-lpwm going from the pi - have hunted the web and not found anyone who has...

    • @rickneill6924
      @rickneill6924 3 роки тому

      I didn't know that Ctrl C resets to all zeros. Thanks for the tip.

  • @nicholasbransonfrancis4685
    @nicholasbransonfrancis4685 4 роки тому

    Please tell me, how to read the actual values displayed on the freq_generator instead of "DOWN" or "FAIL", so that i can compare them with what i wrote/sent to them ??

    • @MartynDavies
      @MartynDavies  4 роки тому

      'read' - see the video

    • @nicholasbransonfrancis4685
      @nicholasbransonfrancis4685 4 роки тому

      @@MartynDavies yes, but I have to type 'read' in the serial monitor to get that. Is it possible to read data and store in a variable and compare with what I wrote, so as to nullify errors?? The thing is, this module doesn't seem to accept the digit '0' in its 2nd decimal place. For instance, if I wanted to write F4.00, it says 'FAIL'. Instead , I had to write either F3.99 or F4.01.

  • @niharchaniyara5489
    @niharchaniyara5489 5 років тому

    Nice work. Thanks for sharing.
    Is there any command to on and off pwm through serial interface?

    • @MartynDavies
      @MartynDavies  5 років тому

      Varying the duty cycle (also known as mark space ratio) is PWM

    • @rickneill6924
      @rickneill6924 3 роки тому

      You need to set the mark space ratio to 0%. This effectively switches the output off.

  • @michaellanderos704
    @michaellanderos704 5 років тому

    I used your code and duplicated the setup. I am able to change the duty cycle using the buttons. When I change the duty cycle serially, the display shows the desired duty cycle however the duty remains unchanged from that set by the buttons. Furthermore I get no responce and nothing when I issue a read command. Based on your experience do you have an idea as to what is going wrong?

    • @MartynDavies
      @MartynDavies  5 років тому

      There should be a response from the module, either 'DOWN' (which is good) or 'FAIL'. If you don't see one of these I would check the wires on the receive side and make sure you have a good connection. A logic analyzer (like I use in the video) can be useful to double check these things, and they are not expensive. As to why the duty cycle is changed on the display, but actually hasn't changed on the wire - I don't know. I wish the manufacturer would open-source the code on the signal generator module so that we can see how it works and make our own improvements.

    • @michaellanderos704
      @michaellanderos704 5 років тому

      @@MartynDavies Thank you so much. Your videos are very helpful.

    • @michaellanderos704
      @michaellanderos704 5 років тому

      Martyn, in any of your tests did you connect an oscilloscope on the output to confirm that the duty cycle was in fact getting changed on command and not just the display?

    • @MartynDavies
      @MartynDavies  5 років тому

      @@michaellanderos704 I've definitely had the scope on this module to see the duty cycle, but can't remember if I was using the serial port at the time...

  • @dhivakaranand
    @dhivakaranand 6 років тому

    Hi Martyn Davies, I'm trying the same program in Arduino Mega. But it's not working for me (pins Rx-10 Tx-11). I couldn't figure out the problem. Is there any methods to diagnose it?

    • @MartynDavies
      @MartynDavies  6 років тому

      Check that you've got the speed correct; try a different pair of pins (in case you've got a damaged Mega); try connecting to a different piece of serial equipment. If you've got a logic analyzer, plug that in to the pins and check if it can see serial data in either direction. The Mega has more than 1 UART interface (3 I think), so you could use these instead of the SoftwareSerial library.

    • @MartynDavies
      @MartynDavies  6 років тому

      You should also check that you have the wiring right - RX on the module to TX on the Arduino and vice versa.

    • @dhivakaranand
      @dhivakaranand 6 років тому

      You're right It was the tx and Rx wiring, thanks

  • @luclucky6621
    @luclucky6621 3 роки тому

    Hi
    I have arduino nano and he doesnt works
    Could you help me please?
    I have the same module pwm and have copy your code
    its ok for arduino nano
    regards

    • @MartynDavies
      @MartynDavies  3 роки тому

      You should probably look at this later video also, since the more recent modules seem to have different firmware in them: ua-cam.com/video/EQJ62frJ5ok/v-deo.html

  • @tlchanal169
    @tlchanal169 4 роки тому

    ทำวงจรสลายซัลเฟตได้หรือเปล่าครับ

  • @baltazar0007
    @baltazar0007 5 років тому

    can i put an antenna on the module at send the square wave over the air to a reciever

    • @MartynDavies
      @MartynDavies  5 років тому

      Not an antenna directly, I don't think. You would probably want to modulate an RF carrier with the squarewave signal. You can get very cheap receiver/transmitter pairs on Aliexpress or ebay (below $2) that would allow you to transmit a signal over the 433Mhz band. Search for 'ASK modulation 433' to find this kind of thing.

    • @baltazar0007
      @baltazar0007 5 років тому

      @@MartynDavies thx alot for your answer i will follow your good work. i am trying to make my arduino send and recieve at very low frequensi so i can monitor movement in some pipes under ground in my house.

    • @MartynDavies
      @MartynDavies  5 років тому

      I want to make a video on these ASK radio modules - I've got some waiting here for me to do that.

  • @MirdaJarab
    @MirdaJarab 5 років тому

    Hi, can Generator be turned on and off through Serial Controls? Thanks.

    • @MartynDavies
      @MartynDavies  5 років тому

      I don't think so

    • @rickneill6924
      @rickneill6924 3 роки тому

      Or do you mean the output of the generator being turned on or off? Setting duty to 0% gives you zero volts out and setting duty to 100% sets the output to Vin (the input voltage).

  • @starlight4038
    @starlight4038 2 роки тому

    Hi, how to use this device in metal detector? thank you

    • @MartynDavies
      @MartynDavies  2 роки тому

      I've never tried to build one, but this guy here has used an Arduino: ua-cam.com/video/505utljY41s/v-deo.html

  • @gartmorn
    @gartmorn 6 років тому

    How easy would it be to use this with an esp8266 to get a remote response? As I said before software isn't my strongpoint!

    • @gartmorn
      @gartmorn 6 років тому +1

      Wrote this before I noticed previous comment!

    • @MartynDavies
      @MartynDavies  6 років тому

      Yes I plan to do this with the Raspberry Pi. The ESP8266 would be possible too, but I think it would be easier to code in Python (on the Rpi) than using the Arduino tools or using LUA (on the ESP)

    • @gartmorn
      @gartmorn 6 років тому

      Martyn Davies it's good to see these modules used in practical situations and not just as test circuit tools!

  • @frexcuadillera1283
    @frexcuadillera1283 4 роки тому

    Hello, I'm using Arduino Mega 2560 for this module and it doesn't work for me
    I used PWM pin 10 and 11 to TXD and RXD respectively, Am I doing it wrong? do I need to use other pins such as TX0 and RX0? thanks

    • @MartynDavies
      @MartynDavies  4 роки тому +1

      I have a Mega somewhere - I'll try to set it up

    • @frexcuadillera1283
      @frexcuadillera1283 4 роки тому

      @@MartynDavies thank you so much!!!!

    • @MartynDavies
      @MartynDavies  4 роки тому +1

      On my Mega I connected 11 to RX on the module and 10 to TX, and the same Arduino script works. The Mega also has 3 additional serial interfaces, e.g. I tried pin 18, 19 to RX,TX on the module, and that works also - although you need to modify the script to use 'Serial1' to address those pins.
      Interestingly, I have a new version of the same frequency module that has slightly different commands on the serial port. I might put that in a video.

    • @kuyafrex480
      @kuyafrex480 4 роки тому +1

      @@MartynDavies previously I tried to use AltSoftSerial.h library and used pins 46 -> RX and 48 -> TX and also works.

    • @kuyafrex480
      @kuyafrex480 4 роки тому

      however the "read" command doesn;t work

  • @akarachsrisom9349
    @akarachsrisom9349 5 років тому

    What is the maximum output current?

    • @rickneill6924
      @rickneill6924 3 роки тому

      Excellent specs and tests here protosupplies.com/product/xy-lpwm-pwm-signal-generator-module

  • @numberformatwoodworking8520
    @numberformatwoodworking8520 6 років тому

    For those of you that have 3d printers I have created a case for this device here: www.thingiverse.com/thing:2863707

  • @harvialiriocastillocuero9565
    @harvialiriocastillocuero9565 6 років тому

    can you please share the arduino code?

    • @MartynDavies
      @MartynDavies  6 років тому

      It's extremely similar to the Software Serial example (www.arduino.cc/en/Reference/SoftwareSerialExample) with the exception of buffering characters until the CR. You can see the code on screen in the video at 6:06. I'll put it up on my github when I have a moment.

    • @MartynDavies
      @MartynDavies  6 років тому

      Code is now on my Github: github.com/magiccow/serial-to-freq-gen/blob/master/serialtofreq.ino

    • @harvialiriocastillocuero9565
      @harvialiriocastillocuero9565 6 років тому

      thanks so much...Nice job

  • @rickneill6924
    @rickneill6924 3 роки тому +1

    I wish I'd watched this before I went through the same learning process. I'm driving my module from an old BASIC computer and eventually realised that the automatically inserted LF/CR needed to be chopped off the end of the data string. I must have a fairly recent production run unit because instead of DOWN I get OK when a data string is received without error. Also at power up/initialise my module sends www.deek-robot.com. Free advertising I guess. In some diagrams found on the 'net the data pin direction arrows are around the wrong way. i.e. TXD coming in and RXD going out. Initially this caused me to wire my connector incorrectly. I've also learned that TXD and RXD (3.3 volt logic) should be level shifted if interfacing with 5 volt logic. It will work with 5 volt logic but it could be stressing circuitry in the module. To be on the safe side, level shifting is recommended.

    • @MartynDavies
      @MartynDavies  3 роки тому

      The newer ones I bought also say deek-robot. The on-board software seems improved.