Ok, so I have 2 Arduino Nano's. Both with HC-12 RF 433mhz serial wireless boards. I have a basic sketch on both using software serial in which I can transmit and recieve string messages between the two.
My goal is:
Arduino 1:
Read 2 x potentiometer readings using AnalogRead (One pot on each analog pin).
En-code the corrosponding values and send via wifi.
Arduino 2:
Decode and read analog values sent by Arduino 1.
Control 2 seperate FET gates via PWM (AnalogWrite) using the values sent from Arduino 1.
I'm fairly new to the RF HC-12 side of things, but I have this circuit working using just one Arduino without any issues. I just need help with coding to intergrate the transmission of the values from one Arduino to the other.
Ideally, latency rates need to be minimul as to provide rapid responce of the FET's.
Ok, I've managed to get Arduino 1 transmitting integer values read from a POT to the PC serial port and the software serial which then feeds to the HC-12. Code below:
When Arduino 1 is not transmitting Arduino 2 displays -1 per line in the serial window. When Arduino 1 is transmitting the serial monitor on Arduino 2 throws out random numbers between 10 and 60 on each line.
You're sending multiple ASCII characters with values in the range 48 to 57, plus newline, but you're receiving individual characters, and printing them as integers.
hmmmmm ok.
Whats the best solution to get around this issue?
I'm unsure as to how to format the data, transmit and then receive it as valid values I can use to then output to a PWM pin.
Well, you can continue sending ASCII characters, but you'll have to change the receiver code to parse the numbers.
Robin2 has a serial handling tutorial thread.
The receiver (Arduino 2) serial window now shows the corresponding values of the POT on Arduino 1 (transmitter) up to 255 bits. But then as the POT value increases beyond 255 on the transmitter, the receiver reaches 255 and then starts counting from 0 again up to 255, then 0 again.
@Groove I have a question with regards to the single byte you mentioned.
Isn't an integer value between -32,xxx and 32,xxx?
So the int input value should allow for values 0 to 1023 to be read no?
Where are you getting the single byte on transmitter concept from? I'm unclear. Thanks.
I imagine s/he means printing the value, as an ASCII string, with some simple delimiter, like a carriage return.
That's what I'd do, then I could very simply verify the result.