Pages: [1]   Go Down
Author Topic: analogRead and generating checksum values  (Read 563 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 36
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Best,
David
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26631
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, atoi would work, but don't forget to terminate the string first.
« Last Edit: September 18, 2010, 10:49:44 am by AWOL » Logged

"Pete, it's a fool 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.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 36
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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) {
            break;
      }
    else {
        checksum += touchStripBuf;
    }
}

Thanks,
David
Logged

Pages: [1]   Go Up
Jump to: