Go Down

Topic: analogRead and generating checksum values (Read 1 time) previous topic - next topic


Hi all,
I think I've been sniffing too many solder fumes, because this question sound pretty straightforward, but I can't seem to figure it out.

Here's my set-up:
I have a couple sensors that pass data via UART to different Rx pins on the mega. I merely read these values, add them to an uberpacket and pass along wirelessly to the host computer on the main Tx pin on the mega. The second-to-last byte in the uberpacket is a checksum value based on all the data in the packet (last packet is line feed, dec 10). The values being read from the other sensors are ascii values, so for 10.5 I read 49 48 46 53. I'm merely passing these values directly, so my checksum is based on 49 49 46 53 (and so on). Everything works great, and can easily verify packets on the receiving machine.

No I am adding data from an analog pin on the mega to the packet. Let's say I get the value of 500 from an analog read. I'm passing this along as an int as part of my uberpacket, and on the receiving end I get 53 48 48. My problem is now calculating the checksum. On the mega it's using the value 500 for the checksum calculation, but on the receiving machine it uses 53, 48 , and 48.

I'm guessing that what I need to do is convert 500 to ascii via itoa() for the checksum? Does this sound right?

Thanks in advance for any pointers.



Sep 18, 2010, 05:49 pm Last Edit: Sep 18, 2010, 05:49 pm by AWOL Reason: 1
Yes, atoi would work, but don't forget to terminate the string first.
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.


something like this (am away from my arduino at the moment, so coding a bit blind):

int touchStrip = 0;
char touchStripBuf[8];

touchStrip = analogRead(touchStripPin);
itoa(touchStripPin, touchStripBuf, 10);
for (int i = 0; i < 8; i++) {
     if (touchStripBuf == 10) {
   else {
       checksum += touchStripBuf;


Go Up