SM0VPO Forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.

New project on sm0vpo.com - Arduino based Radio Control Transmitter Coder

2 posters
Post new topic   Reply to topic

Go down

New project on sm0vpo.com - Arduino based Radio Control Transmitter Coder Empty Re: New project on sm0vpo.com - Arduino based Radio Control Transmitter Coder

Post by sm0vpo Wed Apr 24, 2024 7:49 pm

Hi Ivan,
Many thanks for the info. I would really like to see the completed sketch. I looked briefly at the part you sent by e-mail earlier in the week, but I have received nothing recently: only the one mail from you.

This morning I was up early and also could not sleep last night, so I also wrote and documented the Arduino Nano version of my single-channel servo driver. I tested about 20+ servos, and the differences between them are big. The Arduino recommended servos have very small torque and if the pulses are outside then renge then they go continuously round and round. Those intended for models never do that.

So now I will get my boat painted and assembled. Almost all the bits are printed. We have been promissed some nice weather for the weekend, so hobby work may have to take second place to garden work. Spring is a bit late, with all the snow we have had, even a couple of times this week.

Thank you once again. Catch you later. VBR Harry - sm0vpo

sm0vpo
Admin

Posts : 110
Join date : 2013-03-26
Age : 72
Location : Märsta, Sweden

Back to top Go down

New project on sm0vpo.com - Arduino based Radio Control Transmitter Coder Empty Re: New project on sm0vpo.com - Arduino based Radio Control Transmitter Coder

Post by Ivan Mon Apr 22, 2024 7:38 pm

Hi Harry,

I am sorry to hear bad news about your health. I hope you feel better again.

The code I sent to this conference will not work in your program, but it should work in the project I have sent to you by e-mail. I can send you the whole project again if you wish. The frame duration is defined in the part of creating and initializing global variables - before the setup().

I do not feel as a guru, but I got some experience with single chip MCUs during the last 15 years or so. I started with Parralax Stamp, continued with PICAXE, Arduino, Teensy and now I prefer ESP32.

VBR from Ivan

Ivan

Posts : 794
Join date : 2012-11-25
Age : 64
Location : Praha, Czechia

sm0vpo likes this post

Back to top Go down

New project on sm0vpo.com - Arduino based Radio Control Transmitter Coder Empty Re: New project on sm0vpo.com - Arduino based Radio Control Transmitter Coder

Post by sm0vpo Mon Apr 22, 2024 8:44 am

Ivan wrote:I personally would rather get rid of those us / ms conversions and do it this way:

void loop() {
  digitalWrite(syncPin, HIGH); // Generate sync pulse
  delayMicroseconds(100); // Pulse duration
  digitalWrite(syncPin, LOW); // End sync pulse

  int frameLength = timerInterval * 1000;
 
  // Loop through each joystick
  for (int i = 0; i < pinCount; i++) {
    generateStartPulse(); // Generate pulse
    int joystickValue = analogRead(joystickPins[i]); // Read joystick value
    int pulseWidth = map(joystickValue, 0, 1023, minPulseWidth, maxPulseWidth); // Map joystick value to pulse width
    delayMicroseconds(pulseWidth); // Delay based on joystick value
    frameLength = frameLength - pulseWidth - startPulseDuration;
  }
  generateStartPulse(); // Generate last pulse
  frameLength = frameLength - startPulseDuration;
 
  while (frameLength > 10000) {
    delayMicroseconds (10000);
    frameLength = frameLength - 10000;
  }
  delayMicroseconds (frameLength);
}

Hi Ivan,
Sorry for the delay responding but I have been a bit sick and hardly touched the computer. Yesterday I was in bed the whole day. I had planned to go to Uppsala and take a lady out for lunch. But "The best laid plans of mice and men ..." as they say Crying or Very sad 

Anyway, I can see that you are a bit of a guru when it comes to the the Arduino. I have been programming the Arduino now for quite a long time, almost a week Wink  Most of the programming has been between about 10PM and 2AM in the night. So I am on a slow learning curve. The more I learn so the more I relize that I have a lot more to learn.

Thank you very much for the code suggestion, I am looking forward to trying it out in the next couple of days. Now I have to catch up with all the mundane things I am "supposed" to do (washing bedding/towels/clothes/taking the cat to the vet/Tidying the house ...).

Now that spring is (supposed) to be here I have got loads of things in the garden. I need to move the antenna mast to the center of the garden - I got the council to remove that d**n tree that was overhanging the property, and now there is plenty of space. Maj-Lis used to take care of the garden but now that is a roll I am learning a lot about. It will be 2 years since she passed, this Thursday.

Ok Ivan, thank you once again for the code. I will try it out and come back to you. I do have a couple of questions about this code:
1 - I presume that this is stitched into (replacing bits of) the original code, so the variable are still defined as before?
2 - The frame length should be 25ms for 1 to 6 channels, but extended to 30ms if 8 channels are programmed (always >10ms after channel pulses)

I will add the code and see how it functions. My own method of taking integer, multiplying by 100 and subtracting from remaining time ... etc was a bit crude. But this is what I would have done 35 years ago in the days of GW-BASIC. I still have a lot to lears.

Best regards and have a nice day
Harry - sm0vpo

sm0vpo
Admin

Posts : 110
Join date : 2013-03-26
Age : 72
Location : Märsta, Sweden

Back to top Go down

New project on sm0vpo.com - Arduino based Radio Control Transmitter Coder Empty Re: New project on sm0vpo.com - Arduino based Radio Control Transmitter Coder

Post by Ivan Fri Apr 19, 2024 6:55 am

Hi Harry,

programmed solutions give possibilities to test various versions easily. I personally would rather get rid of those us / ms conversions and do it this way:

void loop() {
  digitalWrite(syncPin, HIGH); // Generate sync pulse
  delayMicroseconds(100); // Pulse duration
  digitalWrite(syncPin, LOW); // End sync pulse

  int frameLength = timerInterval * 1000;
 
  // Loop through each joystick
  for (int i = 0; i < pinCount; i++) {
    generateStartPulse(); // Generate pulse
    int joystickValue = analogRead(joystickPins[i]); // Read joystick value
    int pulseWidth = map(joystickValue, 0, 1023, minPulseWidth, maxPulseWidth); // Map joystick value to pulse width
    delayMicroseconds(pulseWidth); // Delay based on joystick value
    frameLength = frameLength - pulseWidth - startPulseDuration;
  }
  generateStartPulse(); // Generate last pulse
  frameLength = frameLength - startPulseDuration;
 
  while (frameLength > 10000) {
    delayMicroseconds (10000);
    frameLength = frameLength - 10000;
  }
  delayMicroseconds (frameLength);
}


AI will IMHO be a great help to programmers after it gets rid of those silly errors. The drawback is only a few experts will be able to find errors the AI will make and also that the code written by AI may be quite inefficient.

VBR from Ivan

Ivan

Posts : 794
Join date : 2012-11-25
Age : 64
Location : Praha, Czechia

sm0vpo likes this post

Back to top Go down

New project on sm0vpo.com - Arduino based Radio Control Transmitter Coder Empty Re: New project on sm0vpo.com - Arduino based Radio Control Transmitter Coder

Post by sm0vpo Thu Apr 18, 2024 11:59 pm

Hi again Ivan and Co,
Last night I could not sleep so I was up to 4AM working (playing) with the Arduino Nano. It was really interesting and I learned a lot. The problem was to get that 25ms frame timer working so that every frame was EXACTLY equal length, 25ms, no-matter what position any of the joysticks was in - no approximations allowed.

I tried ChatGPT to help me with the code, the same as I did for PIC microprocessors, but it could not generate any code that worked. It gave me the background timer function with an interrupt at 25ms. The joysticks and start pulse timers also use the timer function, so as soon as I inserted any code with a channel timing loop it killed the frame timer. The AI program gave me several attempts but none of them worked. So I went back to basics. I did it the same way I would have done it with GW-Basic (Remember that?).

My solution was to create a 25000μs variable representing the duration of the frame. Every joystic loop reads the joystick and the "map" function gives the timer count for the current joystick in μs: only one timer running in any one instant. I also subtracted the current channel timer value from the 25000μs counter variable. At the end of the 6 joystick loops, the frame-counter variable was left with the exact number of μs needed to run an end-of-frame delay. Easy!

The only complication was that the end-of-frame variable value is always >10000μs and the timer in the Arduino cannot handle such large numbers - it becomes erratic. So I divided by 1000 to get the number of milliseconds as an integer (10 to 22ms) and used that in one delay loop. That worked, but the delay kept jumping between 24ms and 25ms because of the integer approximation.

I converted the ms integer variable back to μs and subtracted it from the end-of-frame variable, which gave the number of μs that were lost with the integer conversion - 0-999μs. That is used in a delayMicroseconds timer to count the last bit of time, and now the frame is always exactly 25ms (+/-1μs) with all setting of all joystick position combinations. No jitter Very Happy  The silent "decoder reset" time to end-of-frame is always 10ms or more. The calculations were done with just two lines of code.

With 8-proportional channels I had to extend the frame rate 30ms to maintain more than 10ms duration for the decoder reset time. I have given the values in the code and the description.
I also reduced the channel pulses to 150μs (spec = 100μs to 200μs).

I have updated the final code in the finished project. Now I will work on more accurate decoder logic. The decoder was designed in the days when four channels was normal (with a long delay), but the timing capacitor is electrolytic; as you are well aware electrolytics are not renowned for accuracy and I have seen variation of -50%.

I will now add web-page links to the project on HHH, but if you have any additional comments I would be really grateful. As I said earlier, I am realy new to Arduino programming and any comments are most welcome.

One lesson learned was that ChatGPT seems to misunderstand that which I believe to be a clear description of a logic function. Instead I now ask it "Please show me how to use the XXXXX function with two worked examples". It does make an excellent teacher Very Happy  but it does make silly mistakes. For the PIC16F628A it tried to use AD0 for analogue input and RA0 for digital output in an A/D example. AD0 and RA0 are both on the same pin-17, and cannot be configured for input and output simultaneously. It also gave me other similar wrong suggestions in "worked examples".

I read that some engineering schools are now teaching students how to use AI for programming, instead of teaching basic programming skills. I suppose they have to make it easier to make engineers when incre4asingly more are needed.

On a more personal level, I have been to Karolinska Hospital for treatment my chronic illness, and a couple of other minor ailments that are developing with age: one of the reasons I could not sleep last night. But now I have serviced my bicycle and I will be using the car a lot less while getting more exercise. I am not as physically active as I was when I was working!

Ok then, it is now midnight. I will catch you later, but it does feel a lot better to be more active with the hobby, now that I have retired.

Very best regards and thank you for your all comments that you gave earlier in the week. All your help is really appreciated. sm0vpo

sm0vpo
Admin

Posts : 110
Join date : 2013-03-26
Age : 72
Location : Märsta, Sweden

Back to top Go down

New project on sm0vpo.com - Arduino based Radio Control Transmitter Coder Empty Re: New project on sm0vpo.com - Arduino based Radio Control Transmitter Coder

Post by sm0vpo Sun Apr 14, 2024 9:32 pm

hi Ivan,
I have updated the pages now and I believe I have covered all your topics.

When I wrote the sketch it was about 1AM last night so I was a bit tired. I have edited the comments a bit so they are more descriptive. I have included the channel decoder from the previous project, but I think I should re-draw it to be more clear and to include 8 channels. Q0 is always high when waiting for a frame. Q1 to Q8 will decode, and Q9 is active after CH-8 has ended, until the reset delay occurs.

Very best regards and thank you for all your help - Harry - sm0vpo

sm0vpo
Admin

Posts : 110
Join date : 2013-03-26
Age : 72
Location : Märsta, Sweden

Back to top Go down

New project on sm0vpo.com - Arduino based Radio Control Transmitter Coder Empty Re: New project on sm0vpo.com - Arduino based Radio Control Transmitter Coder

Post by Ivan Sun Apr 14, 2024 8:33 pm

sm0vpo wrote:I borrowed a couple of "Unbranded" from the grandaughters and the transmitter remained cold after 60 minutes. You could feel that there was a little bit of heat, but not much.

Category: Handheld
Frequency range: 400-470 (MHz)
RF output power: 0.5 (W)
Number of channels: 22 (a)
Theoretical communication distance: 10 (km)
Working voltage: 6 (V)
Frequency stability: 0.5 (ppm)
Theoretical battery life: 24 (h)
Talk time: 5h
Standby time: 4 days
These particular units cost less than $20 for a pair, but the same model is cheaper from e-bay.
Hi Harry,
I see no problem with the transceiver if this is the case.


The very last bit of code is: ...
This sends a final pulse (7th) to end the frame.

I am sorry, but you are not right. The last part of code is a function declaration, which stands outside the loop() and must be called explicitly. According to the P.S. you found that yourself - see later.

I shall work through your comments and also add the decoder (channel seperator) circuit. That would be really interesting, in fact the circuit is already documented elsewhere so the picture is already there on the server.
I have the feeling I have seen it somewhere, but it is better to show it again with this topic.

Perhaps it should be better drawn a little larger and made more clear.
IMHO it is absolutely O.K.

PS - I had to double-check and yes you are 100% correct -  channel 7 is missing
It IS there in fact, but it is merged with the idle interval between the frames.


Generate start pulse, then do the timimng and generate channel-end pulse. Now all 7 channels appear in the serial port AND the oscilloscope:

  generateStartPulse(); // Generate start pulse 
  // Loop through each joystick
  for (int i = 0; i < sizeof(joystickPins) / sizeof(joystickPins[0]); i++) {

    int joystickValue = analogRead(joystickPins[i]); // Read joystick value
    int pulseWidth = map(joystickValue, 0, 1023, minPulseWidth, maxPulseWidth); // Map joystick value to pulse width
    delayMicroseconds(pulseWidth); // Delay based on joystick value
    generateStartPulse(); // Generate channel-end pulse
  }
Yes, this is functionally equivalent
to the code I sent to you. One more generateStartPulse()  than the number of servos is always required, either before or after the cycle. (You still do the repeated calculation of the number of servos.)

VBR from Ivan

Ivan

Posts : 794
Join date : 2012-11-25
Age : 64
Location : Praha, Czechia

sm0vpo likes this post

Back to top Go down

New project on sm0vpo.com - Arduino based Radio Control Transmitter Coder Empty Re: New project on sm0vpo.com - Arduino based Radio Control Transmitter Coder

Post by sm0vpo Sun Apr 14, 2024 7:14 pm

Ivan wrote:Hi Harry,

I sent you my comments via e-mail. Did you get it?

VBR from Ivan
Hi Ivan,
Thank you very much. Yes I have checked the e-mail and I had a quick look at your comments. I will correct and/or answer them shortly.
The walkie-talkies I tried were various. The Baufeng were about $70, but they have a lot of functions. I borrowed a couple of "Unbranded" from the grandaughters and the transmitter remained cold after 60 minutes. You could feel that there was a little bit of heat, but not much.


Category: Handheld
Frequency range: 400-470 (MHz)
RF output power: 0.5 (W)
Number of channels: 22 (a)
Theoretical communication distance: 10 (km)
Working voltage: 6 (V)
Frequency stability: 0.5 (ppm)
Theoretical battery life: 24 (h)
Talk time: 5h
Standby time: 4 days


These particular units cost less than $20 for a pair, but the same model is cheaper from e-bay.



The very last bit of code is:

void generateStartPulse() {
digitalWrite(outputPin, HIGH); // Generate start pulse
delayMicroseconds(startPulseDuration); // Pulse duration
digitalWrite(outputPin, LOW);
}



This sends a final pulse (7th) to end the frame. Although it states "Generate start pulse" it is really generate end pulse. The reason you see A6 (CH-7) included in the script is because I added that to check the function, but forgot to remove it when I copied the code to the HTML page. I totally missed that.


I shall work through your comments and also add the decoder (channel seperator) circuit. That would be really interesting, in fact the circuit is already documented elsewhere so the picture is already there on the server.
New project on sm0vpo.com - Arduino based Radio Control Transmitter Coder Rc_enc_02_dec_cct



Perhaps it should be better drawn a little larger and made more clear.


But thank you for all your comments, I really do appreciate them.


VBR Harry - sm0vpo



PS - I had to double-check and yes you are 100% correct -  channel 7 is missing, but I do get the serial data from the in the Serial Display panel (debug print commands added)!

Very Happy

Generate start pulse, then do the timimng and generate channel-end pulse. Now all 7 channels appear in the serial port AND the oscilloscope:

  generateStartPulse(); // Generate start pulse
 
  // Loop through each joystick
  for (int i = 0; i < sizeof(joystickPins) / sizeof(joystickPins[0]); i++) {

    int joystickValue = analogRead(joystickPins[i]); // Read joystick value
    int pulseWidth = map(joystickValue, 0, 1023, minPulseWidth, maxPulseWidth); // Map joystick value to pulse width
    delayMicroseconds(pulseWidth); // Delay based on joystick value
    generateStartPulse(); // Generate channel-end pulse
  }


sm0vpo
Admin

Posts : 110
Join date : 2013-03-26
Age : 72
Location : Märsta, Sweden

Back to top Go down

New project on sm0vpo.com - Arduino based Radio Control Transmitter Coder Empty Re: New project on sm0vpo.com - Arduino based Radio Control Transmitter Coder

Post by Ivan Sun Apr 14, 2024 2:34 pm

Hi Harry,

I sent you my comments via e-mail. Did you get it?

VBR from Ivan

Ivan

Posts : 794
Join date : 2012-11-25
Age : 64
Location : Praha, Czechia

sm0vpo likes this post

Back to top Go down

New project on sm0vpo.com - Arduino based Radio Control Transmitter Coder Empty New project on sm0vpo.com - Arduino based Radio Control Transmitter Coder

Post by sm0vpo Sun Apr 14, 2024 10:43 am

Hello again all,
Yesterday it rained so that I was not able to spend any time in the garden (as retired people are supposed to do!!). So I decided to learn a bit more about the Arduino, mainly because my Analogue RC Encoder board is a bit big for the full 6 channels. I would also like to have 8-channel proportional, which introduces a timing problem with the "Futaba timing standard". This I have also fixed.

Last night I could not sleep, so I photographed and documented the results of my learning and programming. This I will share with you on my homepages at:
https://sm0vpo.com/pic/6ch-rc-enc_arduino.htm

@ Ivan - if you could take a look at it and give any open comments I would be really grateful

I have NOT yet linked the project on the homepages, but this I will do after I have rectified any errors or suggestions for improvements.

My page differes from "Traditional Arduino" sites in that I didn't just give a bunch of script and a picture - "monkey-see, monkey-do" style. The only component is the Arduino Nano (or Uno) and nothing else. A wiring table is more than adequate, IMHO. I have however, taken the time to explain my code so that even if you have little knowledge of the Arduino, like me, then you can still understand it and modify it to suit your own needs.

@ Densil - Your points were taken about 433-MHz band and interference to car remote locking systems. Although it is not a major problem, it is "sailing close to the wind". I am now using a pair of $15 PMR band walkie-talkies for both TX and RX. Heck of a range, simple, no modules, quick, cheap and easy.

Have fun with it and best regards from Harry - sm0vpo

sm0vpo
Admin

Posts : 110
Join date : 2013-03-26
Age : 72
Location : Märsta, Sweden

Back to top Go down

New project on sm0vpo.com - Arduino based Radio Control Transmitter Coder Empty Re: New project on sm0vpo.com - Arduino based Radio Control Transmitter Coder

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

Post new topic   Reply to topic
 
Permissions in this forum:
You can reply to topics in this forum