Hello!
I've wrote a script in python which sends data through PC's bluetooth to HC-06 on arduino.
"state" is integer from 0 to 1000 (it is controlled through potentiometer)
...
gaugeSocket.send(str(state))
...
I have a problem, because I can't get right character to integer conversion on arduino (from HC-06 serial).
Serial print gives me this (if I turn potentiometer from 0 to 1000):
0ÿ(0ÿ(0ÿ(0ÿ(0ÿ(0ÿ(0ÿ(60(1ÿ(00(16(0ÿ(23(0ÿ(30(0ÿ(3ÿ(60(43(0ÿ(49(0ÿ(53(0ÿ(5ÿ(90(69(0ÿ(88(0ÿ(10(00(10(00(10(
What am I missing?
Thank you[/I]
I've wrote a script in python which sends data through PC's bluetooth to HC-06 on arduino.
"state" is integer from 0 to 1000 (it is controlled through potentiometer)
...
gaugeSocket.send(str(state))
...
I have a problem, because I can't get right character to integer conversion on arduino (from HC-06 serial).
Code:
SoftwareSerial mySerial(10, 11); // RX, TX
char buf[2];
int i=0;
int data;
int ledPin = 9;
void setup() {
pinMode(ledPin, OUTPUT);
// Open serial communications and wait for port to open:
Serial.begin(57600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
mySerial.begin(9600);
}
void loop() { // run over and over
if (mySerial.available()) {
for(;i<2; ){
buf[I] = mySerial.read();
i++;
}
i = 0;
Serial.print(buf);
data = atoi(buf);
}
analogWrite(ledPin, data/10); //To see how code behaves on LED
}
0ÿ(0ÿ(0ÿ(0ÿ(0ÿ(0ÿ(0ÿ(60(1ÿ(00(16(0ÿ(23(0ÿ(30(0ÿ(3ÿ(60(43(0ÿ(49(0ÿ(53(0ÿ(5ÿ(90(69(0ÿ(88(0ÿ(10(00(10(00(10(
What am I missing?
Thank you[/I]