HC-06 data receiving

Status
Not open for further replies.

electruc254

Newbie level 1
Joined
Sep 17, 2015
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
11
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).


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 = mySerial.read();
      i++;
    }
    i = 0;
    Serial.print(buf);
    data = atoi(buf);
  }

    analogWrite(ledPin, data/10); //To see how code behaves on LED
}

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
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…