Nov 13, 2011

Sunday night with Bluetooth

What do you do after installing your Christmas lights? Build a robot of course!


This projects started with a modified version of the Boe-Bot on which I added big dirt wheels scavenged from a dead RC car. The simple structure on top is made with my usual LEGO spider-legs system supporting the Arduino and its proto shield. I'm using the Sparfun proto shield since it has a build-in connector for the BlueSmirf Bluetooth breakout board and.. it's red. I also use two power supplies to separate the servos from the rest of the electronics.

Software wise, I used the Sena BTerm app to do some direct communication with the Bluetooth device. This app was very practical since it enabled me to only code on the Arduino side. This made prototyping very fast. The only real work began when I had to make the real Android app using Bluetooth. For that I hacked Google's BluetoothChat demo and after a short time I was using buttons and sliders to communicate with my Arduino. Why was that work? Eclipse...


A great advantage of using an Android device as the communication platform is the real-time outputs. This is very nice when debugging since you don't have to be tether with the laptop.

Edit 1: I later created an Arduino to Arduino link with bluetooth.

Edit 2: Here is similar code a later used for the minirccar



#include  
int leadPin = 3;
//Servo myservo;  // create servo object to control a servo
int servoDir = 90;
int delayTime = 100;
int incomingByte = 0;
int motorState = LOW;
int servoPin = 8;
char gBtMsg[256]; 
void BtReceive(void){
  bool keepReading = true;
  int index = 0;

  gBtMsg[0] = '\0';

  while(keepReading){
    keepReading = false;
 
    if (Serial.available() > 0) {
      // read the incoming byte:
      incomingByte = Serial.read();
      if(incomingByte != 13){
        gBtMsg[index++] = incomingByte;
        keepReading = true;
      }
    }
  }

  gBtMsg[index] = '\0';
void BtSend(char* i_pBtCmd, bool i_ln = true){
  if(i_ln){
    Serial.println(i_pBtCmd);
  } else{
    Serial.print(i_pBtCmd);
  }

  delay(100);
  BtReceive();
void setup()
{
  pinMode(leadPin, OUTPUT);
  pinMode(servoPin,OUTPUT);

  Serial.begin(115200);
  BtSend("$$$", false);
  BtSend("SM,0");
  BtSend("---");
}

void loop()
{
  bool doSomthing = false;
  if (Serial.available() > 0){
    incomingByte = Serial.read();
    doSomthing = true;
  }
  switch(incomingByte){
  case '1':
    servoDir = 1360; //left
    break;
  case '2':
    servoDir = 1580;//90;
    break;
  case '3':
    servoDir = 1800; //right
    break;
  case '4':
    motorState = HIGH;
    break;
  case 'd':
    motorState = LOW;
    break;
   default:
     doSomthing = false;
  }
  for (int temp = 0; temp <= 2 && (doSomthing || (motorState == HIGH)); temp++)
  {
    digitalWrite(servoPin,HIGH);
    delayMicroseconds(servoDir);
    digitalWrite(servoPin,LOW);
    delay(25);
  }

  digitalWrite(leadPin, motorState);

  delay(delayTime);
}



60 comments:

  1. Good project design buddy..... great work appriciated

    ReplyDelete
  2. Can you share Arduino code?
    I want to do something like this but it involves Netdruino.

    ReplyDelete
    Replies
    1. I couldn't find this old project but I've added (in the 'Read more' section of this post) the code from the MiniRCCar project which is almost the same. Hope this can help.

      Delete
  3. Hi Phillipe,
    I'm trying to build a project using an HC-06 module, but am having some really basic problems that I thought with your experience, you might be able to help me with.

    They are:
    1. when I use it to connect a BT USB dongle on my XP laptop with my PC on COM1 using RealTerm terminal emulator on both sides and sending ASCII data at 9600,N,8,1, instead of receiving 7-bit ASCII alpha-numerics, I'm receiving high-order characters. In both directions.
    For example when sending
    1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ
    I receive (in HEX)
    E0 00 00 E0 00 E0 00 00 E0 E0 00 E0 E0 E0 00 E0 00 00 E0 00 00 E0 00 E0
    E0 00 E0 00 E0 E0 E0 E0 E0 E0 E0 00 E0 E0 E0 E0 E0 E0 E0 E0 E0 00 E0 E0
    00 E0 E0 E0 E0 E0 E0 E0 E0 E0 E0 E0 E0 E0 00 E0 E0 E0 00 E0 E0 E0 00 E0
    E0 00 E0 E0 00 E0 E0 E0 E0 E0 E0 E0 E0 E0 E0 E0 E0 E0 00 E0 E0 E0 E0 E0
    E0 E0 E0 E0 E0 E0 E0 00 E0 E0 E0 00 E0 E0 E0 00 E0 E0 E0 00 E0 E0 E0 00
    E0 E0 E0 00 E0 E0 E0 00

    2. I'm unable to talk to the device (over the serial side). Sending AT when the unit is not paired and the LED flashing, I get no response.

    Being a software guy, I blamed the hardware and bought a second HC-06 to check. But no, this one was worse!, I could only get one-way comms (serial ->BT) > the two devices are different models.
    So that didn't solve my problem.

    ReplyDelete
    Replies
    1. Other example of garbled message:
      Send :THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG
      receive (in HEX):
      D5 AB FD 5D 55 6D 79 69 BF 7B 5B 61 51 63 BF 73 61 4F BF 6B 55 65 5F 75
      77 BF 61 53 75 5B BF 57 6F 75 BF 67 7D 4B 4D BF 77 61 71 BF E5 EB 00

      Delete
  4. In case you didn’t already found it, go check this post I did about using the HC-05.
    My initial guess here is that you probably don’t have the right connection speed set on your modules. You can query what the current setting is with “AT+UART?”.

    ReplyDelete
  5. Hi Phillipe,
    After spending a couple of hours with me, Lyman suggested I contact you with the introduction "I sent a good friend of mine some of these modules to "tool" around with as he is a genius with BT".

    Yes, thanks, I read your blogs on HC-05. Unfortunately they are Arduino-oriented, and I'm not at all familiar with Arduino.
    I'm working with a bare breadboard and cables direct to my PC, picture here: http://gpsanimator.com/tmp/BT1.jpg
    I have already built a java app for my Android phone which successfully locates and communicates with a separate device - an i-Blue 747 GPS data logger. This app locates the device, receives position data (NMEA) , monitors the connection and if dropped (by the GPS powering down or going out of range) re-establishing the connection.
    What I'm targeting with the HC-06 project, is to develop the phone app talk to our racing yacht's navigation system (a B&G H2000 Performance processor) over its RS232 port, through which commands and queries can be directed to the processor and present useful tactical info in real time.

    I believe you're correct about a problem with the connection speeds. The problem is that, as I mentioned in my initial comment, I'm unable to establish the AT communication.
    I have 2 HC-06 boards from different suppliers with different markings:
    The original one, I'll call Board 1, is marked JY-MCU V1.06. The second Board 2 has fewer markings: A logo of SJ in a circle and a BT logo. Both have the CSR and MX chips and identify themselves as HC-06 during pairing.
    Only Board 2 provides 2-way comms, the Board 1 only transmits serial-> BT. Both display the message garbling I described earlier.
    I have tried Lyman's suggestion of setting the KEY pin high, but that didn't help. And reading the Chinglish documentation, it would appear that this only applies to the HC-05 to switch between Master and Slave.
    So I am unable to get a response to AT commands.

    I know the solution is simple, and obvious, but after over a week of trial and error, I just can't nail it.

    ReplyDelete
    Replies
    1. Hi friend of Lyman! You are welcome in the land of PhilBlog.
      The fact that your boards only have 4 header pins may mean that mounted modules are not able to be access in command mode. Still, lets assume we can.
      To enter the command mode on the HC module you must 1) Have the module powered down (no power on the VCC) 2) Set the Key pin to HIGH 3) Power up the mmodule (power on VCC) 4) Start using the AT commands.
      Also When opening the COM port to the module use the following settings: "38400,0,0" (Stop bit 0, Parity bit 0)

      Delete
    2. Thanks for your suggestions, however I'm still making no progress.
      I followed your instructions re the KEY pin: remove power to VCC; put + 4.5 on KEY pin; Put + 4.5 V on VCC; attempt AT comms on serial port at 9600,N,8,1 Still no response from HC-06.
      I tried a range of other speeds: from 1200 through 38,400 no change.
      Re your suggestion to open COM port at 38400,0,0: My terminal emulator doesn't support Stop Bit 0. Did you mean 1 stop bit?
      The following observations may not be relevant, but I provide them in hope.
      I have 2 LEDs on the board one on the TXD and one on the RXD lines. On on Board 2 the TXD line sets high on power up, even when communicating "gibberish" over the BT port. On board 1, the TXD line only goes high during data transmission.
      The second observation is if I power up either of the boards with the COM port connected to the PC, its LED remains off, indicating it's not starting? If I disconnect the serial cable, it powers up and flashes as usual at around 2Hz.

      One post I read indicated the need to provide ~5ms between characters in the AT command. I have tried with a range of 0 through 15 ms without success.

      Another post talks about the need for line termination or not after the AT, I have tried both with and without.

      Delete
  6. 스포츠토토티비
    토토사이트


    very good and unique article, thanks for sharing, keep up the good work.

    ReplyDelete
  7. Great beat ! I wish to apprentgice at tthe same time as you amend yor site, how can i subscribe for a blog website?
    Thee account aided mee a applicable deal. I have been a little bit familiar of this your broadcast provided bright clear concept


    스포츠토토
    토토사이트

    ReplyDelete
  8. Just a smiling visitor here to share the love (:, btw outstanding layout.


    카지노
    카지노사이트


    ReplyDelete
  9. play online slots The most comfortable in the era of playing slots, real money, full support, must be PGSLOT168.INFO only. We mainly focus on creating an impression of using the service for members. We give unlimited bonuses and free credits. สล็อต

    ReplyDelete
  10. 2. Must study the game very well and then place a full bet. You should study the game first whether the game is giving out prize money or not. If the game still has prize money distribution, you can To go in and play because there is a chance that you can win money from that game, so the way to watch people is easy to watch from the most popular games at the moment and you can follow other people. at all pgslot

    ReplyDelete
  11. The way to work is convenient can also make himself an independent life take care of yourself because I can tell that From working since graduating, not taking a break for 6 full years, definitely not making money to pay installments like a condo in the BTS area. สล็อต

    ReplyDelete
  12. Pgslot. If you ask that the online gambling game Getting real money or not, it depends on you. select website pgslot

    ReplyDelete
  13. life with a bright future. Sometimes it is unavoidable that darkness comes into our lives, superslot

    ReplyDelete
  14. Exciting online earning site We would like to be a part of the success of all gamblers. บาคาร่า

    ReplyDelete
  15. good, which at present have developed a variety of game formats, resulting in a betting system that can attract gamblers as well as There are superslot เครดิตฟรี

    ReplyDelete
  16. actors are sometimes just the best actors for major roles. However, these films might justifiably be called whitewashed if the majority of films produced over a given span of time fit this amb

    ReplyDelete
  17. make money online Today we will put together the correct way to cure insomnia, which you can study if. ambbet

    ReplyDelete
  18. Dragon's tongue (helps absorb toxins, the property is air purification, absorbs toxins, vapors type benzene, formaldehyde ambbet

    ReplyDelete
  19. Therefore, it is a website that is number 1 in Thailand of all online gamers. to enjoy playing more easily Whether it is a deposit system or a withdrawal system, บาคาร่า ออนไลน์

    ReplyDelete
  20. All profits from this song go to Metallica’s All Within My Hands Foundation and St. Jude Children’s Research Hospital บาคาร่า

    ReplyDelete
  21. free credit slots is another channel of people playing online slots games that often asks for free credit to play without you No need to believe, need capital jili

    ReplyDelete
  22. Winbig Slot, a website that provides the best quality services in this era. Convenient and fast service and reliable superslot เครดิตฟรี

    ReplyDelete
  23. ust have a horoscope The chances of taking home the jackpot are very high.It is also a game that has a variety of styles according to the player's own preferences. ambbet

    ReplyDelete
  24. It's the time of making your money, it will not fall to someone else's. And that every beat is ours, that means we have to spend money. amb

    ReplyDelete
  25. Pgslot big deposit, spin rich, first deposit of the day, make 3 times the balance, withdraw 100 times ข่าวบอลล่าสุด

    ReplyDelete
  26. transforming it into a huge jackpot for overwhelming slots jackpot for overwhelming slots spinners fans superslot

    ReplyDelete
  27. Enter to play excellent slots, find modern services. Beautiful web page, easy to use. PGSLOT web game provider. pgslot

    ReplyDelete
  28. The website includes all slots, starting at 1 baht, the website has the right to modify, change สมัครสมาชิกสล็อต pg

    ReplyDelete
  29. Online slots, slots, direct web, slotxo, online games on mobile, deposit - withdraw, top-up with automatic system pgslot

    ReplyDelete
  30. in playing that is different from playing in other Therefore, playing online slots games in this often make money for amb

    ReplyDelete
  31. Online slots games on mobile phones, top up, withdraw via automatic system, deposit-withdraw in 5 seconds only. pgslot เว็บตรง

    ReplyDelete
  32. So if you want to keep a child from gambling online then all the online casinos should be regulated and monitored, not banned. pgslot

    ReplyDelete
  33. Previously, you had to display all rows of pictures side-by-side. But today may not be necessary. sexybacarat

    ReplyDelete
  34. Fish shooting game. If talking about this game, no one will know for sure. especially the players ambslot

    ReplyDelete
  35. al money because our webal money because our website provides good slot games. Aes. And the website is สล็อต

    ReplyDelete
  36. New casino, AMBBET.BAR, new arrival, very modern system
    because at present welcome ข่าวบอลล่าสุด

    ReplyDelete
  37. therefore have to develop oneself To be able to be equal with anyone, new games, new pgslot เว็บตรง

    ReplyDelete
  38. Go with the money that has a high mula to occupy. The online format requires credibility pgslot

    ReplyDelete
  39. apply for a few steps also with very simple conditions Give new members a 50% bonus. Popularity of playing online games. pgslot

    ReplyDelete
  40. Download PG SLOT, a collection of leading slot games, beautiful 3D images, the number 1 pgslot

    ReplyDelete
  41. Some scatter slots require 3 or more symbols on reels 2 3 4 only for a total of 15 free spins to be awarded to the player for a total of 15 free spins. pgslot เว็บตรง

    ReplyDelete
  42. these questions? If we think that we will go into the investment line There must be such questions in everything we decide to play, trade pgslot

    ReplyDelete
  43. Slots on the web, straight, iPhone, make real money every day. There are a variety of games to try out. สล็อต

    ReplyDelete
  44. by playing slot games must stay in the game for as long as possible By playing the game must last for 30 pgslot

    ReplyDelete
  45. Let you know about slot games. New trend like talisman, a slot game that doesn't matter. how will you play pgslot

    ReplyDelete
  46. When depositing money to the website for the first time, therefore, should use the bonus received. pgslot เว็บตรง

    ReplyDelete
  47. Have a lot of money There is only 1 baht coin. You can start applying and playing too. ผลบอลสด

    ReplyDelete
  48. The latest web slots The direct website does not go through the agent here. Give away 100 free credits. superslot

    ReplyDelete
  49. Slots, online games, mobile slots, top-up-withdrawals via automatic system, 24 hours service, 100% stable and safe AMBKING

    ReplyDelete
  50. "Slot formula calculated with AI" from us, just apply to play SPADE GAMING with us right now at AMB website. AMBKING

    ReplyDelete
  51. players often break. Don't forget to turn on eye protection mode as well.
    Preparing a battery back-up device near the body
    pgslot

    ReplyDelete
  52. joker123 online slot game Open for service 24 hours a day, deposit-withdrawal, secure, 100% safe ข่าวบอลวันนี้

    ReplyDelete
  53. This comment has been removed by the author.

    ReplyDelete