I've bought a module which should communicate via serial RX/TX. The module and code are described here: https://www.dfrobot.com/wiki/index.php/Weather_Station_with_Anemometer/Wind_vane/Rain_bucket_SKU:SEN0186.
I've hooked up everything as described (using an Arduino Nano instead of an Uno, but the rest is the same) and now trying to get things to work. I could not get any decent output. So I decided to switch to a bare-minimum program to read stuff from the serial port in order to see whats going on. I found the following sample: https://gist.github.com/Protoneer/96db95bfb87c3befe46e and implemented this code (only this).
Now what I see is the following:
- With RX/TX connected the wrong way, when I reset the nano, the serial monitor shows me one instance of the string I'm looking for (as described in the module documentation). When connected the right way, the text is not there but that's to be expected as the nano should receive it (and not the serial monitor). This does however prove that the module is actually sending data.
- Serial.available
seems to evaluate to 0 all the time, indicating there is no data to be read from the serial line.
So why would Serial.available
return 0 even though there seems to be data being sent to serial, as the monitor does show the string I'm looking for with the pins crossed. I have also tried disconnecting the RX line on the module to prevent statements being sent over serial to interfere with the module. The documentation does not state the need to send anything to the module in order to trigger the response. In fact, if you look at the sample code the first interaction with serial (after Serial.begin(9600)
) is Serial.available()
.
Is there anything else I can do from a debug perspective? As you might notice I'm no expert in this stuff.
1 Answer 1
It seems you have the module connected to the Nano pins 0 and 1, and are also trying to communicate with the PC via the Serial
object and serial monitor?
There is a USB/serial converter chip on the Nano that is likely conflicting with your module. You can try SoftwareSerial to get a bit-banged serial port for communicating with the module on some other pins.
-
you mean pins 0 and 1 - RX and TX?08/27/2018 14:18:17Commented Aug 27, 2018 at 14:18
-
Corrected answer to refer to RX/TX pins 0/1.jose can u c– jose can u c08/27/2018 14:19:29Commented Aug 27, 2018 at 14:19
-
How is it conflicting? The device only sends data to RX of Nano. TX is not connected to the device so the Nano doesn't send data to the device, only to USB. Nothing is sent from computer to Nano and it would not stop the device.08/27/2018 14:41:32Commented Aug 27, 2018 at 14:41
-
1@Juraj , well even if nothing is sent from the computer, the tx of the usb-serial chip is connected (with a resistor) to the rx of the atmega chip. josecanuc, for 9600 baud, I prefer the AltSoftSerial.Jot– Jot08/27/2018 14:48:52Commented Aug 27, 2018 at 14:48
-
This indeed fixed it, SoftwareSerial on pins 10 and 11 works as expected.Jasper– Jasper08/27/2018 17:24:00Commented Aug 27, 2018 at 17:24
Serial
object and serial monitor? There is a USB/serial converter chip on the Nano that is likely conflicting with your module. You can try SoftwareSerial to get a bit-banged serial port for communicating with the module on some other pins.