Hi Folks. I finally think I need some help with code.
I’m just a casual Arduino tinkerer, getting old, brain not working like it used to.
I am retired and so only hobbies with no commercial interest.
The code concerned is here, on the Dronebot Workshop so is easy available to see.
I wish to combine the 433Mhz Tx/Rx using the Radiohead library Demo2 where Bill uses a DHT22.
With the waterproof, Ultrasonic Transducer, the A….. that is compatible with the …….
My project is to combine both sketches in a manner that allows me to measure the height of a tank of water & Transmit it to a Receiver, some distance away.
The Communications video is at https://dronebotworkshop.com/433mhz-rf-modules-arduino/#Resources
The Ultrasonic video is at https://dronebotworkshop.com/waterproof-ultrasonic/
Bill uses the JSN-SR04T sensor in Mode1 and is equivalent to the A02YYUW dual element sensor I am using.
My hardware set up is on 2 breadboards as I need a Receiver 433Mhz as well.
Here is the Rub. And because the wiring uses all different Arduino pins, I can upload each sketch, separately and get them to work OK.
So, 433Mhz sketch ….. no problem by itself.
Upload the Ultrasonic sketch …. no problem by itself.
Try to merge both to get at minimum, just the Temperature and Humidity, =Various problems.
I have hacked the code, tried to “fault-find” and found some peculiar results but just can’t seem to hone on the root cause.
So, here I am. Cursing the hours I have spent to make a Tank Water level transmitter.
I’m hoping that a forum member could assist me.
I would prefer not to take this request any further and waste your time, if no-one feels up to the task.
I will work out, tomorrow how to update my hopelessly hacked code. It’s a mess.
The other problem is you need to take my word on what the Receiver is displaying on another PC, lest you have to build the hardware.
Regards, JimJtron.
@jimjtron Hi, can you post the error you are receiving?
Is it a compile error,, or a run error.
If a compile error, capture just the first few lines (in red) of the error, any following errors aren't important at this stage. I am attaching a picture of what I mean. Do NOT use the 'Copy error messages' button.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
@jimjtron Might be a classic 'buffer overflow' issue. The addition of msg1 provides a place for msg to overflow. Just a shot in the dark, but look at everything that affects the length of the string defined by msg in case something is a byte too long.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
Thanks Ron. I'll check but the original code without msg1 worked without issue.
So I have not tampered with that section. I'm still highly suspicious that the Ultrasonic's code method is "hogging" the time needed for the *msg to slowly transmit out.
Anyhow, an update.
This is the receivers output with the TimeStamp feature turned ON.
Started here:-
14:13:09.484 -> Humidity: - Temperature:
14:13:22.712 -> Humidity: - Temperature:
14:13:31.576 -> Humidity: - Temperature:
14:13:40.416 -> Humidity: - Temperature:
etc.
14:41:08.972 -> Humidity: - Temperature:
14:41:22.228 -> Humidity: - Temperature:
14:41:26.978 -> Humidity: 50.00 - Temperature: 23.40
14:41:31.045 -> Humidity: 50.00 - Temperature: 23.40
14:41:39.909 -> Humidity: 50.00 - Temperature: 23.40
14:41:53.155 -> Humidity: 50.00 - Temperature: 23.40
14:42:02.002 -> Humidity: 50.00 - Temperature: 23.40
14:42:10.865 -> Humidity: 50.00 - Temperature: 23.40
14:42:15.255 -> Humidity: 50.00 - Temperature: 23.40
14:42:24.118 -> Humidity: 50.00 - Temperature: 23.40
etc.
So the Delay is 14:41 minus 14:13hrs. = 28 minutes !!!
It would be interesting to know WHY ?????
Regards, JimJtron.
@jimjtron Ok, I am confused, if the original code worked, why did you change it which I gather broke it. Very confused.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
@jimjtron Why is the timestamp not sequential?
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
// ************************************************
// ADD this piece from Radiohead examples for debugging purposes.
const char msg1 = "hello"; // removed * before msg1
rf_driver.send((uint8_t *)msg1, strlen(msg1));
rf_driver.waitPacketSent();
delay(200);
// ************************************************
// ADD this piece from Radiohead examples for debugging purposes. const char msg1 = "hello"; // removed * before msg1
Just an FYI: - Removing the asterisk is a complete mistake, and should not even compile.
Do you have your compiler warning turned up in your preferences?
By removing that, you're actually introducing bugs in your code.
Cheers
@frogandtoad I wonder what will happen if he removes 1 char from hello, that may change the memory addresses going from 5 to 4. I am still 100% convinced he has a buffer overflow issue that is stomping on some critical piece of memory. It's been decades since I used gcc, is there a compiler directive that will show the address map of the compiled code, and how do you pass compile time switches in the arduino IDE?
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
@frogandtoad I wonder what will happen if he removes 1 char from hello, that may change the memory addresses going from 5 to 4. I am still 100% convinced he has a buffer overflow issue that is stomping on some critical piece of memory. It's been decades since I used gcc, is there a compiler directive that will show the address map of the compiled code, and how do you pass compile time switches in the arduino IDE?
It's possible, but I did not review the whole code... the missing pointer was the first thing I spotted, which is 100% incorrect. There seems to be a whole mix of legacy C code with a sprinkle of C++ code here... a great recipe for problems 🙂
@frogandtoad IIRC, he did say he is very new so we may have a 'playing with sharp knives' issue here and the blood is obscuring the details.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.
Thanks to all for your replies.
I think it’s best if I summarise what happened BEFORE I started hacking / adding code.
Code from the Drone Workshop’s 2 seperate examples (JSN-SR04T sensor in Mode1 )
and from the 433Mhz Tx/Rx using the Radiohead library Demo2 where Bill uses a DHT22.
Both these sketches compile without error and work fine on the same UNO if Uploaded and run separately.
No buffer overflow issues. No delay in transmission …. All good.
Movements in front of the Ultrasonic Sensor….. all responded quickly.
I proceeded to combine them without changing or adding any code.
The Ultrasonic code was gradually added to the original 433Mhz code.
In the void loop()section I added the Ultrasonic code before the Radio code.
So the only change I made then was to move the “{“ from the bottom of the Ultrasonic code
to the last line of the sketch.
No compile errors. No code additions, no alterations (except “{“) downloaded OK.
No response at the receiver.
After that, I started experimenting and then posted where I left off.
Which I apologise, must have been confusing.
I think next I will go back and change the “original merge” within the Void Loop() and place
the Radio code first, and the Ultrasonic code last, initially, without changing anything.
****** will get back to you sometime when I have done this. ******
Cheers for now. JimJtron 6/4/22.
Oh Dear! How utterly embarrassing. I found the problem. I made a copy of only the Radio 433Mhz code
that works with the DHT sensor. Slowly I added the declarations from the Ultrasonic sketch. (All OK)
Then from the Void setup sketch, each line of code uploaded so I could see the incoming messages still arrived on the other UNO. Until I added "mySerial.begin(9600);" Then it stopped sending. So what was it? Very simple. int pinRX = 11; int pinTX = 10; Wrong way around !!!!! Doh!!
Hours have been burned. Off to the PUB to drown my sorrows. Then back to finishing the project.
Regards, Village Idiot.
Update. Looks like I spoke too soon. With the pins around as original, the 433Mhz transmissions wont work but the Ultrasonic sensor does. Visa Versa. I just started to progress the new code and found that, after correcting the above, I had reliable transmissions to the other Uno. But turning on the Serial monitor at the Transmitter / Sensor Uno, I had no "Distance" measurements. So I changed to .... mySerial(11,10) and now I get distance measurements to the Serial Mon. but no longer get 433Mhz transmissions to the Receiver. Time to change the wiring ???