Go Down

Topic: Convert streaming ASCII to Text to read Battery Monitor Data (Read 174 times) previous topic - next topic

sdingman

I am a newbie and would like to get some guidance on how to proceed with a project that I'd like to pursue.

I have a Bogart Engineering TM-2030A Battery Monitor. It has a phone jack connector J2 that allows one to pickup on real time data of constantly repeating ASCII data stream at 2400 baud, 8N1, from pin 4 of that connector.

A link to Bogart Engineering pdf explaining what data is available and how to access it:

https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=54&cad=rja&uact=8&ved=0ahUKEwjY4b76-LXTAhVj7YMKHUX8COA4MhAWCDYwAw&url=https%3A%2F%2Fforum.arduino.cc%2Findex.php%3Faction%3Ddlattach%3Btopic%3D300438.0%3Battach%3D114382&usg=AFQjCNFYb0z-8hAllWHZnMJaySUAHgPrkg&sig2=y4LX3KPU0uLjrsVFi83rOQ

I would like to read in this streaming data to my Arduino Uno and on back to my computer to veiw in Serial Monitor for starters. Eventually I'd like to stream this data into Excel in real time so that I can analyze it, plot it, etc.

One of the pieces of data that is output is Battery % of charge, that the TM-2030 calculates. I will use this value to create a window comparator to trigger an external relay to switch back to Grid power when the battery % of charge goes below a Low set point, then switch back again to Inverter power when the battery % once again returns to a higher set point.

I did a test using the Digital Button sketch:

https://www.arduino.cc/en/Tutorial/Button

I replaced the button switch with the interface circuit suggested by Bogart Engineering. It worked, and I got 0's and 1's down column 1 of the Serial Monitor. So it works, but I'm not sure what kind of sketch to use to actually get text to be captured with the Serial Monitor.

I would like a little guidance.

avr_fred

You'll first need to understand the format of the data being set from the controller since the documentation says what is sent but not how it is sent. The best way to start would be a USB to Serial adapter like a FT232 or CH340G available on eBay for $1 to $5, depending upon type. If you have a Chinese UNO, you most likely already have drivers installed for the CH340G so I'd go that direction if that is the case. If you have a genuine Arduino then I'd probably go with the FT232 type.

Get the USB<->serial adapter working at 2400 baud and connect to a terminal program on your PC with the battery monitor attached. Observe the data that arrives and see if broken up into individual strings that are terminated with a CR (carriage return) LF (line feed) pair or just an endless stream of data. This will determine how you setup your UNO - to just capture characters, which you then need to parse into data, or entire strings which can be taken apart a bit easier.

You'll want to look at the Serial.read function to actually handle the incoming data. Your PC can be reading the same string in parallel, that is having the input of the UNO and PC USB adaptor driven from the same serial output of the monitor.

sdingman

Thank you avr_fred for the quick response. You said,

"the documentation says what is sent but not how it is sent."

I'm confused by your comment because from the documentation, it says,

"The TM-2025 real time data (no logged data) comes out from Pin 4 on J2 as a constantly repeating ASCII data stream at 2400 baud. (The usual: 8 bit, parity none, stop bits=1) For example, the amps and watts show as "A=3.3, W=36.7" The output "high" volts
(+5V) is "mark" or "idle" state. "Start bit" (logic 0), is about 0 volts.)"

Doesn't this statement tell how the data is sent? Since I mentioned that I tested the data stream using the Digital Button sketch, and got a column of 0's and 1's down column 1 of the Serial Monitor and doesn't this also mean that it is already in a serial format (one bit after another)?

I have a genuine Arduino Uno. The new Arduino Uno that I have:

https://www.amazon.com/Arduino-Uno-R3-Microcontroller-A000066/dp/B008GRTSV6

The description says:

The Uno differs from all preceding boards in that it does not use the FTDI USB-to-serial driver chip. Instead, it features the Atmega16U2 (Atmega8U2 up to version R2) programmed as a USB-to-serial converter. 

So doesn't this mean that the Arduino Uno already has a USB to Serial adapter?

Your last sentence is puzzling. I'm not sure how to interpret what you mean since there is only data going in one direction, and that is into my computer from the Arduino Uno.

Grumpy_Mike

Quote
I would like to read in this streaming data to my Arduino Uno and on back to my computer to veiw in Serial Monitor for starters.
The Uno only has one serial port and that is designed to talk to your computer through the USB / serial converter.

So to read the data from your instrument using the software serial libiary using two other pins at 2400baud. Then use the built in serial port at a higher speed, say 9600 baud to send what you read to the computer.

Lots of help on the net, here is one link plucked at random from the net:- http://arduinobasics.blogspot.co.uk/2012/07/arduino-basics-simple-arduino-serial.html

sdingman

Thank you Grumpy_Mike for your response. As I have written in my response to avr_fred, The TM-2025 real time data (no logged data) comes out from Pin 4 on J2 as a constantly repeating ASCII data stream at 2400 baud. So to try to read the data at any other baud rate, such as 9600 baud, all I get returned is gibberish.

When I originally set up the Digital Read Serial to receive this data stream, I did try other baud rates, other than 2400 baud, just to see what would be displayed. The results were nonsensical characters being displayed horizontally across the Serial Monitor window. When I set the baud rate to 2400 baud, I got one bit per row as per the Line Feed provided by:

Code: [Select]
Serial.println(buttonState);

Grumpy_Mike

Quote
So to try to read the data at any other baud rate, such as 9600 baud, all I get returned is gibberish.
I didn't say that. I said send to your computer at 9600 baud and read from software serial at 2400 baud.
You need to write out faster than you read in so that your input buffer doesn't overflow.

Quote
I got one bit per row as per the Line Feed provided by:
Which is rubbish.

Do you know about asynchronous data? That is what you are trying to receive. You can only do this on a Uno with software serial. Have you read that link I posted?

avr_fred

2400 baud, 8 data bits, no pairity and "A=3.3, W=36.7" does not define how data is being sent, only a small subset of it. You need to see what comes out of the battery monitor in total before you can start taking it apart, programmatically.

Research (translation - Google) what Mike has said about software serial on the Uno and what I said about a USB to serial converter. Those are two of the key pieces you need in order to do what you've asked.

Here's a good assignment for you - draw a schematic of how you connect the battery monitor, the UNO and your PC together. Nothing fancy, paper and pencil will do. Then post a photo or a scan of what you've drawn.

Robin2

I suggest you try the second example in Serial Input Basics with a small change. The original uses the newline character '\n' as the end-marker. If you change that to a comma I think it will receive and display your data.

Also modify it so it uses your SoftwareSerial instance rather the Serial - assuming you are following @Grumpy_MIke's advice.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

sdingman

Wow, You all have given me much to chew on, Choke, Choke. I'll get back when I've had a chance to digest a little, maybe tomorrow, or the next. I'll also include a drawing. Thank you all so much.

Grumpy_Mike

@fred
I thought th bit that said
Quote
(+5V) is "mark" or "idle" state. "Start bit" (logic 0), is about 0 volts.)"
Along with the serial data format told you the signal was an RS232 signal sent at TTL levels.
Not sure what more you need to know.

sdingman

@avr_Fred, Robin2, Grumpy_Mike

Quote
Here's a good assignment for you - draw a schematic of how you connect the battery monitor, the UNO and your PC together. Nothing fancy, paper and pencil will do. Then post a photo or a scan of what you've drawn.
I'm not a programmer but I did go through the exercises in the links provided and set up many of the examples in the tutorials. There is much to be confused about. I'm not sure of how to modify a sketch that I see in an example to suit what I'm trying to do. 
One particular confusion point is in many of the built in examples, such as Digital Read Serial, the input pin is defined like: 
Code: [Select]
int pushButton = 2;

and so since this sketch uses pin 2 as an input I used that sketch to experiment with.
In Serial Input Basics, that uses the keyboard as input, so no pins are involved, so no example for me to use. 
Robin2 said, 

Quote
Also modify it so it uses your SoftwareSerial instance rather the Serial - assuming you are following @Grumpy_MIke's advice.
I'm confused by this as well. since there is no defined pin for the input, like Digital Read Serial. You suggested that I use the Example 2, except modify it to recognize a comma, that's easy. But what pin do I put my signal into? I see no pin identified as an Input pin.
Grumpy_Mike said:
Quote
I said send to your computer at 9600 baud and read from software serial at 2400 baud.
You need to write out faster than you read in so that your input buffer doesn't overflow. 
I know how to set the Arduino Uno to read at 2400 using:
Code: [Select]
Serial.begin(2400);

but I don't know how to set up the coding to send to my computer at 9600 baud. Every time id set the Serial Monitor to anything other than 2400 baud, I got gibberish. This pin connecting issue is hanging me up.

avr_fred

From the "Serial" reference page:

Quote
Serial is used for communication between the Arduino board and a computer or other devices. All Arduino boards have at least one serial port (also known as a UART or USART): Serial. It communicates on digital pins 0 (RX) and 1 (TX) as well as with the computer via USB. Thus, if you use these functions, you cannot also use pins 0 and 1 for digital input or output.
So perhaps part of your confusion is that when you use the Uno's native serial port on digital pins 0 and 1, you are only connecting to your battery monitor, there is no provision to attach your PC. This is why Mike said you need the "software serial" library which would be used to create the second serial port. It would be easiest to use the existing USB connection to your PC, outputting to the monitor window in the Arduino IDE and use software serial for the 2400 baud connection to your battery monitor.

BTW, still no attachments show in your previous posts so still not able to further explain since I don't know how things are connected.

sdingman



Grumpy_Mike

Quote
But what pin do I put my signal into? I see no pin identified as an Input pin.
Any pin on an Arduino can be used as an input pin. With software serial YOU define what pins you want to use.

Quote
but I don't know how to set up the coding to send to my computer at 9600 baud.
You use:-
Code: [Select]
Serial.begin(9600);
You set the SOFTWARE serial rate at 2400 because is that is how you communicate with your device.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy