I'm having trouble figuring out how to start my project. The objective is to control a robot with four servo motors and six DC motors through bluetooth. I have a bluetooth shield from Adafruit and I'm using the Arduino UNO. Ideally, I want to control this robot by sending it packets through Processing. The problem is I don't know how to create a packet with a header, payload, and checksum. I can't find any examples; can anyone help me find something to help me get started?
|
Start simple.
See below video. You need to use the SPP profile. see https://learn.sparkfun.com/tutorials/bluetooth-basics/bluetooth-profiles Make sure your purchased bluetooth device supports SPP. Some bluetooth device are permanently setup to do one fix action. However, many bluetooth need to be 'programmed' (told what to do) before doing the task via AT command. Set speed, pairing, etc. https://learn.sparkfun.com/tutorials/using-the-bluesmirf/example-code-using-command-mode http://www.instructables.com/id/Modify-The-HC-05-Bluetooth-Module-Defaults-Using-A/ |
|||||||||
|
First, depending on the degree of reliability you need, you may not actually have to do this yourself, as the bluetooth implementation will already invisibly-to-you add, verify, and remove a packet and checksum framing around your data. But let's assume you want to add your own as well. A packet is a batch of data to be transmitted as a contained unit. It may or may not contain exactly one useful message, but it is quite convenient if it does, and since you will be doing your own packetization (at this level) you can make sure that it does. So basically you will transmit something that has a structure, for example:
There are countless ways you could implement this, but your life will be a lot easier if you make both the messages and the packet structure human readable, so that you can watch on the serial monitor, and perhaps even type manually. So let's say you did something like
For simplicity sake, instead of having a "Hi I'm a packet" header, we just use the newline character '\n' to mark the end of a packet, and assume that whatever comes next is the start of a new packet. Further, since bluetooth is already creating a one-to-one link, you don't need to address who you are talking to. Now we have a message, for example "M1=200" meaning "drive motor 1 at PWM level 200" (out of 255). I'm somewhat randomly choosing the '/' character to mark the division between the message body and it's checksum. "BF" might be the low two hex digits of adding up all the previous bytes in this message (it's not, I just picked something random). And finally you have your newline to mark the end of a message and the end of a packet, since in this scheme we've decided that 1 packet = 1 message. For extra fun, if the robot itself is not dangerous, you can make a test mode where the receiver will accept messages with no '/' and checksum, and only check the checksum on those where it is present. This would allow you to manually type messages into a terminal when you are experimenting. Or you can make your own specialized terminal program which calculates and appends a checksum each time you press return |
|||
|