I'm using Arduino Mega and I'm trying to communicate with device for measuring temperature, wind speed etc. via RS232. It's Hot wire anemometer TMA-21HW, which has USB mini port and I also found RS232 protocol in manual.
I made this connection: Anemometer -> USB cable -> adapter USB to RS232 -> RS232 to TTL adapter (MAX3232) -> Arduino
I tried following code:
but I'm getting random numbers on Serial monitor..I also add to the code "Serial2.write("A") to send command "A" to the device and start communication but it didn't work. I'm new to stuff like this and I'm not sure if the code is problem or connection...I checked other posts on this forum and others but still nothing..
Wiring from RS232-TTL (MAX3232) adapter to Arduino is:
VCC -> 5V
GND -> GND
RXD -> TX2
TXD -> RX2
I also tried switching RX and TX between adapters and to Arduino but nothing works.
I can't give specific sdvice just now, but a trick that can cut your work down a bit might help.
Figure out all the various settings for the "conversation" and see who says what to whom…
...all without involving any Arduino or code you wrote.
Do this using a terminal emulator like PuTTY or CoolTerm running on your desktop machine.
Use the same common sense that got you this far, it seems, and hook the device to be controlled directly to your desktop machine, and try, then succeed, to establish a connection where you can type stuff and see the responses.
This will make experiments go way faster. Baud rate, stop bits, line endings and so forth can all be tweaked just by playing around in CoolTerm (my pick) or PuTTY.
Once you have a working ability to talk and listen, and have run it through some good fraction of its paces, transfer that knowledge to an Arduino sketch just as simple as you can make it, like the one you have, and see if it doesn't also… work.
Thank you for your advice I know CoolTerm so I'm trying it right now...All I'm getting is something like this, but when I'm moving with the device it's changing so maybe it's sending some values about wind speed...or something else.
The device looks like this:
On the LCD display it shows measured data..so I'm thinking if I "pick" right bytes, or those what I need and display them in correct format..It could work (maybe)
EDIT: Okay, on Byte 27,28 I can see right value of wind speed
So the next step is to read the serial input basics tutorial
which has a demo-code that shows how to use start- and endmarkers
which in your case are the "02" and the "03"
to receive the characters into an array and then you can pickout the bytes for further processing the data
I tried only the "B" command which lights up the display of the anemometer (it worked). I'm not sure if I will use commands (if I don't have to) to get those 2 or 3 values that I need. Maybe the way to do this is read all 33 bytes, save them and then pick those which I need...I will try both ways
It's almost midnight here so I will continue tomorrow and let you know how it went
OK, THX. good luck, though luck should not enter into it.
There seem to be other 02 bytes, but the 03 start byte may be unique.
I wonder if waiting to see 02, then 03 next woukd be enough to sync you up, then you can receive and count bytes ignoring them until you are going to receive bytes for the real data, at which point you could stash them in your variables.
The link to Robin2's tutorial would have worn out long ago if links did that. Wear out from so much use.
But all I get is: Arduino is ready
I'm wondering...maybe I'm wrong with the way how I define the endMarker when it's 03 ...I tried to write it also in a different way like "03", 03...
What do you think about the code?
EDIT: The USB cabel that goes from anemometer to reduction USB-RS232 is USB 2.0 and the reduction is USB 1.1 ...could it be problem? Between those two I also have reduction with 2 female USB ports so I can connect the USB cabel from anemometer and USB-RS232 reduction. Right know I had to connect it like this because I had no other choice
I connected the USB-RS232 cabel to the notebook but CoolTerm didn't even find it..it says that there is no available serial port...So I think a will have to buy one with USB 2.0
Not necessarily. You may only be missing a driver for whatever in the final cable is doing the conversion.
But that may not be the next best step, driver diving.
We can probably test this in a different way.
Please hand draw the entire franken-cable that you are trying to use to go between the anemometer and the Arduino. Note any USB version, although I do not think that is a problem.
My understanding. Is wrong as you have stated you are gender bending the USB. Which seems odd. I've got everything you can think of around the lab and no USB gender correcting capability. Never needed it.
Maybe I'm missing something here, but where is the USB host device in this chain? I've used the USB-RS232 cable from post #16 in the past, but it needs a USB host (like a PC) to tell it what to do.