Hi there, Im having an issue where I am sending values from one an Arduino Nano, connected to a Joystick over a bluetooth module.
These values are being changed from the joysticks range of 0-1023 to 0-255 to be sent through the serial function. The other Arduino Uno receives these, but also has some random values along each line.
For e.g, when the joystick is in a neutral position, it should read 128128 (xAxis yAxis) but instead there are:
4950
5649
5056
Before returning back to 128128
The fluctuations in numbers is the issue. Any ideas on how to solve this?? Would be much appreciated, hopefully im missing something small.
Here is the Master code (Arduino connected to Joystick):
int xAxis, yAxis;
void setup() {
Serial.begin(38400);
}
void loop() {
xAxis = analogRead(A1);
yAxis = analogRead(A2);
Serial.write(xAxis/4);
Serial.write(yAxis/4);
Serial.print(xAxis/4);
Serial.println(yAxis/4);
delay(20);
}
Now the Slave Code - (Arduino picking up these values):
int xAxis, yAxis;
void setup()
{
Serial.begin(38400);
}
void loop()
{
while (Serial.available() >= 2)
{
xAxis = Serial.read();
Serial.print(xAxis,DEC);
delay(10);
yAxis = Serial.read();
Serial.println(yAxis,DEC);
}
}
And i have attached a screenshot of the serial monitor when the joystick is in a neutral position.
I am using a DFRobot Bluetooth Module, which has been correctly setup and paired as a slave and master.