A short test program for all things m3pi and BtBee.
Dependencies: btbee m3pi_ng mbed
Fork of m3pi_btTest by
Diff: main.cpp
- Revision:
- 3:545c4c50dc0f
- Parent:
- 2:35d1143053d3
- Child:
- 4:31939848b5ba
diff -r 35d1143053d3 -r 545c4c50dc0f main.cpp --- a/main.cpp Tue May 14 11:05:52 2013 +0000 +++ b/main.cpp Thu May 16 12:09:39 2013 +0000 @@ -1,23 +1,24 @@ #include "mbed.h" #include "m3pi_ng.h" - +#include "btbee.h" m3pi m3pi; +btbee btbee; DigitalOut mbed_led[] = {(LED1), (LED2),(LED3), (LED4)}; DigitalOut m3pi_led[] = {(p13), (p14), (p15), (p16), (p17), (p18), (p19), (p20)}; DigitalIn m3pi_pb(p21); Timer t1; -Serial btbee(p28, p27); // tx rx -DigitalOut btbee_reset(p26); // 0 resets the device +//Serial btbee(p28, p27); // tx rx +//DigitalOut btbee_reset(p26); // 0 resets the device -//Serial btbee(p27, p28); // tx rx int main() { // initialization stuff //////////////////////////////////////////////////////////////////////////////////////////////////// m3pi.locate(0,1); - btbee_reset=1; // else it keeps resetting + //btbee_reset=1; // else it keeps resetting + btbee.reset(); for (int i = 0; i <4; i++) { mbed_led[i] = 0; } @@ -25,10 +26,13 @@ m3pi_led[i]=0; } m3pi_pb.mode(PullUp); // expected would be 1 when pb is pressed, 0 when not, opposite is the case - //btbee.baud(38400); // this is BtBee default for AT commands + // NOTE on baud rate: the baud rate to be used has to be set on the btBee beforehand. this uses the at mode which is activated by hardware switch. + // only use the hw switch while powered off. use the configure_btbee program to write to it. + //btbee.baud(9600); // this is BtBee default for regular commands + btbee.baud(115200); // this is BtBee regular command set baud rate //btbee.format(); // the default should be fine - // end initialization stuff //////////////////////////////////////////////////////////////////////////////////////////////// + // end initialization stuff //////////////////////////////////////////////////////////////////////////////////////////////// /* THIS IS NOT DOCUMENTED??? Where does the m3pi::printf function come from? m3pi is a child of Stream so it must be from there, probably defined using the m3pi::print function... @@ -56,12 +60,13 @@ while (true){ m3pi_led[0]=!m3pi_pb; } - - while(m3pi_pb){ - m3pi_led[5]=!m3pi_led[5]; - wait(0.1); + */ + ///* + while(m3pi_pb) { + m3pi_led[0]=!m3pi_led[0]; + wait(0.1); } - */ + //*/ // test what happens if i try to read from serial and nothing is there @@ -73,14 +78,14 @@ mbed_led[0]=1; */ - ///* + /* int rawsens[5]; int sens1; int t_sig1; float fl; while(true) { t1.start(); - m3pi.raw_sensor(rawsens); + m3pi.raw_sensor(rawsens); t_sig1=t1.read_ms(); //wait(0.1); m3pi.cls(); @@ -95,35 +100,49 @@ t1.reset(); m3pi_led[0]=!m3pi_led[0]; } - //*/ + */ - /* + ///* int ii=1; int pos=0; + int write = 1; + char c; + char arr_read[30]; + int chars_read; while (true) { m3pi_led[0]=1; m3pi_led[1]=0; - if (btbee.writeable()) { - if (ii==6){btbee.printf("end\n");} - else {btbee.printf("Sensor %d. : %d \n",ii,rawsens[ii-1]);} - m3pi_led[0]=0; - ii++; - m3pi.locate(0,0); - m3pi.printf("Sent %0.3d",ii); + if (btbee.writeable() && write ) { + if (ii==6) { + btbee.printf("end\n"); + write=1; + } + //else {btbee.printf("Sensor %d. : %d \n",ii,rawsens[ii-1]);} + else { + btbee.printf("Line %0.3d \n",ii); + m3pi_led[0]=0; + m3pi.locate(0,0); + m3pi.printf("Sent %0.3d",ii); + ii++; + } } - while (btbee.readable()) { - c = btbee.getc(); - m3pi.locate(pos,1); - m3pi.print(&c,1); - pos++; - pos=pos%8; - + //c = btbee.getc(); + //m3pi.locate(pos,1); + //m3pi.print(&c,1); + //pos++; + //pos=pos%8; + m3pi_led[7]=1; + btbee.read_all(arr_read, 30, &chars_read ); + m3pi_led[6]=1; + m3pi.locate(0,1); + m3pi.print(arr_read,chars_read); + m3pi_led[5]=1; } - - wait(0.5); + pos=0; + wait(0.1); } - */ + //*/ }