Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

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

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top