Go Down

Topic: No serial communication working with Romeo V2 board (Read 497 times) previous topic - next topic

Eric31

Feb 27, 2013, 07:34 pm Last Edit: Feb 28, 2013, 06:38 am by Coding Badly Reason: 1
Hello, I have a Romeo V2 board and I want to use serial communication from Romeo to computer (via USB).
My SW is simple: when switch are pushed, a led lights and a message should appear on the Serial screen.
The compilation works, the led switch when I push each buttons (OK), but I do not see any message on the serial screen... (my IDE is 1.0.3). I see the port of the board (COMX) => OK, I define the type of board and the serial port in TOOL. but still no message...
Please, can someone help me?
Help!

Code: [Select]
#include <SoftwareSerial.h>
char msgs[5][15] = {
"Right Key OK ",
"Up Key OK ",
"Down Key OK ",
"Left Key OK ",
"Select Key OK"};
char start_msg[15] = {
"Start loop "};
int adc_key_val[5] ={
30, 150, 360, 535, 760 };
int NUM_KEYS = 5;
int adc_key_in;
int key=?1;
int oldkey=?1;
void setup() {
pinMode(13, OUTPUT);
Serial.begin(9600);
delay(1);
/*Print that we made it here*/
/* Serial.println(start_msg);*/
Serial.println(NUM_KEYS);
delay(1);
}
void loop()
{
digitalWrite(13, LOW);
adc_key_in = analogRead(0); // read the value from the sensor
/* get the key */
key = get_key(adc_key_in); // convert into key press
if (key != oldkey) { // if keypress is detected
delay(50); // wait for debounce time
adc_key_in = analogRead(0); // read the value from the sensor
key = get_key(adc_key_in); // convert into key press
if (key != oldkey) {
oldkey = key;
digitalWrite(13, HIGH);
delay(1000);
if (key =0){
Serial.println(adc_key_in, DEC);
delay(1);
Serial.println(msgs[key]);
delay(1);
}
}
}
}
// Convert ADC value to key number
int get_key(unsigned int input)
{
int k;
for (k = 0; k < NUM_KEYS; k++)
{
if (input < adc_key_val[k])
{
return k;
}
}
if (k = NUM_KEYS)
k = ?1; // No valid key pressed
return k;
}



Moderator edit: [code] [/code] tags added.

Coding Badly


It would be most helpful if you used auto-format in the IDE.

Code: [Select]
if (key =0){
...oops.

Code: [Select]
if (k = NUM_KEYS)
...oops.

PaulS


Nick Gammon

Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Go Up