Hello all, I think I may have bit off more than I can chew based on my level of knowledge. I have no prior programming background so I probably don't know a lot of things that are taken as common knowledge. I do however have a desire to learn new things which is what I'm doing here.
What I am trying to do is collect a return voltage read from a variable resistance hall effect sensor attached to the arduino. I need to take that reading and insert it into a message string and transmit that serially to a radio with a checksum as the last byte. The checksum is a XOR of all the preceding bytes for example:
Message string = V;RB0475;
Checksum Calculation = 56 XOR 3B XOR 52 XOR 42 XOR 30 XOR 34 XOR 37 XOR 35 XOR 3B
New Message String = V;RB0475;<checksum byte>
I have been sifting through forum posts for 2 days now and I think I have confused myself more than anything. I'm not even sure what have done so far is sufficient to get the job done.
Here is my code as it sits now where the output is correct without a checksum.
/*
Hall_Effect_Read
Reads an analog input on pin A5, converts it to voltage, multiplies by 100 to remove "." which is an unsupported character by the radio.
Calculates a checksum using XOR and appends values to the end of the string.
*/
//clear existing setup
void setup() {
///init serial comms
Serial.begin(9600);
}
// Loop for testing, final revision will be run once per power cycle
void loop() {
//turn pin 9 on to full power
analogWrite(9, 255);
//wait 5ms for sensor to settle
delay(5);
// read the input on analog pin A5:
int sensorValue = analogRead(A5);
// Convert the analog reading to a voltage and multiply by 100 to remove decimal point:
float voltage = sensorValue * (5.0 / 1023.0) * 100;
//Setup message format (probably a more efficient way to do this
//convert voltage to something other than float value since I can't add the float value to a string (errors out)
word voltvalue = voltage;
//set lead in string for radio protocol
String Header = "V;RB0";
//add voltage
String Read = Header + voltvalue;
//add final seperator before checksum bit
String Transmission = Read + ";";
//turn pin 9 off
analogWrite(9, 0);
// print out the message before checksum (FOR TESTING PURPOSES REMOVE A WHEN COMPLETE)
Serial.println(Transmission);
//calculate Checksum
//add checksum to transmission
//transmit message serially
//delay X seconds between reads REMOVE WHEN COMPLETE
delay(3000);
}
I think I need to convert what I have to an array to actually perform the checksum calculation, but I'm not sure.
I do know that I will need to convert the ascii string to individual bytes and convert those to hex to do the checksum which is what leads me to the array conversion.
Can someone point me in the right direction or give me a sample of code that will do this and I can parse through it an learn what the functions are doing knowing that I'm not chasing a rabbit down a hole?
Thanks.
P.S. Really enjoy reading these forums and seeing the amount of help that is offered.