Jump to content

HC05 bluetooth serial question

Recommended Posts

Hi! I am trying the following code in Energia


int firstSensor = 0;    // first analog sensor
int secondSensor = 0;   // second analog sensor
int thirdSensor = 0;    // digital sensor
int inByte = 0;         // incoming serial byte

void setup()
 // start serial port at 9600 bps:
 pinMode(2, INPUT);   // digital sensor is on digital pin 2
 establishContact();  // send a byte to establish contact until receiver responds 

void loop()
 // if we get a valid byte, read analog ins:
 if (Serial.available() > 0) {
   // get incoming byte:
   inByte = Serial.read();
   // read first analog input, divide by 4 to make the range 0-255:
   firstSensor = analogRead(A0)/4;
   // delay 10ms to let the ADC recover:
   // read second analog input, divide by 4 to make the range 0-255:
   secondSensor = analogRead(1)/4;
   // read  switch, map it to 0 or 255L
   thirdSensor = map(digitalRead(2), 0, 1, 0, 255);  
   // send sensor values:
   Serial.println(firstSensor, DEC);
   Serial.println(secondSensor, DEC);
   Serial.println(thirdSensor, DEC);               

void establishContact() {
 while (Serial.available() <= 0) {
   Serial.println('A');   // send a capital A


The terminal (hyperterm in Windows) is showing the expected "A" characters, but I am unable to type in any input. It looks like hyperterm just ignored anything typed in. Where could be the problem? Thanks in advance.

Link to post
Share on other sites

Hi pine,


Which MSP430 do you have in the LaunchPad? I just now ran your code on a msp430g2553 and it works as expected.

1: On reset I see a continuous stream of 'A'.

2: On any key press connection is establised and I see the 3 analog values being printed.


If you are running on a msp430g2231 then try changing the baudrate to 4800 with Serial.begin(4800);



Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...