Offline
Full Member
Karma: 1
Posts: 238
|
 |
« on: January 22, 2013, 09:57:38 am » |
I'd like to control the BlinkM led via Bluetooth wireless. I'm using the following code to start. Currently I have BlinkM plugged into Vin -> +5v, GND -> GND, d = A4 (SDA), c = A5 (SCL). How can I alter this code so I can give commands via the serial monitor configured to the BT port (COM5 SPP) and BT baud rate (115200) and have it be recognize by the Arduino Pro? When performing the experiment the Arduino Pro would only receive power using a 12v power adapter (barrel jack port) and the A-B serial cable would be disconnected.
|
|
|
|
|
Logged
|
peace*&^
|
|
|
|
Queens, New York
Offline
Edison Member
Karma: 28
Posts: 1563
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #1 on: January 22, 2013, 10:09:48 am » |
So whats not working? What are you using to send the commands to and from the computer? What program, Putty, Hyperterminal,or something else? Did you do a run a test to see if the two communicate before starting a project? Write a bare basic, simple program to continously send out "TEST" from the arduino, through the BT module and see if the computer gets "TEST" back. If it doesn't then there is a setup problem.
|
|
|
|
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Offline
Full Member
Karma: 1
Posts: 238
|
 |
« Reply #2 on: January 22, 2013, 10:35:43 am » |
What's not working is supplying commands to affect the led. The pic may be deceiving since BlinkM is lit, however the bluetooth module led is not green meaning it is not paired with the PC. Previously, I have successfully performed a test to prove BT is communicating over RX/TX on Arduino Pro and it used Arduino Serial Monitor to print counter result. I was thinking to still use the Serial Monitor to type in my commands. I'm confuse how to use both UART and I2C together. The sketch loading on the board now was attached to the original post, but it doesn't implement the BT technology I have connected. Thanks.
|
|
|
|
|
Logged
|
peace*&^
|
|
|
|
Queens, New York
Offline
Edison Member
Karma: 28
Posts: 1563
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #3 on: January 22, 2013, 11:27:46 am » |
That BT module use I2C or RX/TX? If it is RX/TX, then use software serial. If it is I2C then lookup some sample codes to get it to work with the Wire library. I haven't used I2C with bluetooth before, so im not sure how to code it myself. But just do a search for I2C bluetooth and see what you get.
|
|
|
|
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Offline
Full Member
Karma: 1
Posts: 238
|
 |
« Reply #4 on: January 22, 2013, 04:03:26 pm » |
That BT module use I2C or RX/TX? If it is RX/TX, then use software serial. If it is I2C then lookup some sample codes to get it to work with the Wire library. I haven't used I2C with bluetooth before, so im not sure how to code it myself. But just do a search for I2C bluetooth and see what you get.
The BT module uses RX/TX. The BlinkM is I2C. I will investigate further. any help is appreciated.
|
|
|
|
|
Logged
|
peace*&^
|
|
|
|
Queens, New York
Offline
Edison Member
Karma: 28
Posts: 1563
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #5 on: January 22, 2013, 04:06:08 pm » |
Post your code, with the code tag #, I cant open your attachment at work.
|
|
|
|
« Last Edit: January 22, 2013, 04:15:17 pm by HazardsMind »
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Offline
Full Member
Karma: 1
Posts: 238
|
 |
« Reply #6 on: January 22, 2013, 04:47:41 pm » |
I understand i need to use SoftwareSerial to identify RX/TX. Then I suppose I can somehow integrate that into this code to control the BlinkM. Thanks! /* * BlinkMScriptWriter -- Example of how to write light scripts * * BlinkM connections to Arduino * PWR - -- gnd -- black -- Gnd * PWR + -- +5V -- red -- 5V * I2C d -- SDA -- green -- Analog In 4 * I2C c -- SCK -- blue -- Analog In 5 * * Note: This sketch resets the I2C address of the BlinkM. * If you don't want this behavior, comment out "BlinkM_setAddress()" * in setup() and change the variable "blink_addr" to your BlinkM's addr. * * * 2007-8, Tod E. Kurt, ThingM, http://thingm.com/ */
// so we can see BlinkM_funcs working #define BLINKM_FUNCS_DEBUG 1
#include "Wire.h" #include "BlinkM_funcs.h"
int blinkm_addr = 0x09;
// the example script we're going to write blinkm_script_line script1_lines[] = { { 1, {'f', 10,00,00}}, { 10, {'c', 0x21,0x22,0x23}}, // dim white { 10, {'c', 0x41,0x42,0x43}}, // dim white { 10, {'c', 0x61,0x62,0x63}}, // dim white { 10, {'c', 0x81,0x82,0x83}}, // dim white { 50, {'c', 0xa1,0xa2,0xa3}}, // dim white { 50, {'c', 0xfd,0xfd,0x01}}, // mostly orange { 50, {'c', 0x02,0xfe,0xfe}}, // mostly teal }; int script1_len = 8; // number of script lines above
char serInStr[30]; // array that will hold the serial input string
void help() { Serial.println("\r\nBlinkMScriptWriter!\n" "'W' to write the script\n" "'R' to read back the script\n" "'p' to play back the script indefinitely\n" "'o' to stop script playback\n" "'0' to fade to black\n" ); }
void setup() { BlinkM_beginWithPower();
BlinkM_setAddress( blinkm_addr ); Serial.begin(19200); byte rc = BlinkM_checkAddress( blinkm_addr ); if( rc == -1 ) Serial.println("\r\nno response"); else if( rc == 1 ) Serial.println("\r\naddr mismatch");
help(); Serial.print("cmd>"); }
void loop() { //read the serial port and create a string out of what you read if( readSerialString() ) { Serial.println(serInStr); char cmd = serInStr[0]; int num = atoi(serInStr+1); if( cmd == 'W' ) { Serial.println("Writing new script..."); BlinkM_writeScript( blinkm_addr, 0, script1_len, 0, script1_lines); Serial.println("done."); } else if( cmd == 'R' ) { Serial.println("Reading back script..."); } else if( cmd == 'p' ) { Serial.println("Playing Script 0 repeatedly"); BlinkM_playScript( blinkm_addr, 0,0,0 ); } else if( cmd == 'o' ) { Serial.println("Stopping Script 0"); BlinkM_stopScript( blinkm_addr ); } else if( cmd =='0' ) { Serial.println("Fade to black"); BlinkM_fadeToRGB( blinkm_addr, 0,0,0); } } }
//read a string from the serial and store it in an array //you must supply the array variable uint8_t readSerialString() { if(!Serial.available()) { return 0; } delay(10); // wait a little for serial data int i = 0; while (Serial.available()) { serInStr[i] = Serial.read(); // FIXME: doesn't check buffer overrun i++; } serInStr[i] = 0; // indicate end of read string return i; // return number of chars read }
|
|
|
|
|
Logged
|
peace*&^
|
|
|
|
Queens, New York
Offline
Edison Member
Karma: 28
Posts: 1563
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #7 on: January 22, 2013, 06:53:19 pm » |
Quick question, have you tried to just turn a LED on and off yet via Bluetooth? Before you start this project, make sure you understand the basics. Start with a single LED, and let me know how that goes.
|
|
|
|
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W, Gameduino
Arduino Tutorials, coming soon.
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Offline
Full Member
Karma: 1
Posts: 238
|
 |
« Reply #8 on: January 22, 2013, 09:49:38 pm » |
I think that's a good idea because I haven't done that yet. I'll take smaller steps forward.
|
|
|
|
|
Logged
|
peace*&^
|
|
|
|
|