Controlling ShiftBrite and reading Compass using mbed websocket server
Purpose
This project was to see how to use a websocket to both read in commands from a server as well as send information to the server. To accomplish this we decided to use the compass data to post to the server and a shiftbrite to respond to data from the websocket server.
Description
To set up the webpage you go to http://sockets.mbed.org/your_own_channel . From there open up the view in one tab and the send in another. The send page will be how you send information to your mbed the view will show what you send to the mbed as well as what the mbed sends to the server. When the mbed first connects to the server it send a msg saying "MBED Connected". After you receive this msg on the view page you can switch to the send page and send either a command to request the compass data or a command to change the shiftbrite colors and brightness.
Syntax
The commands we decided to implement to send to the mbed are at max 3 characters. Sending a "C" will tell the mbed to send the compass data to the server. Sending a "0" will tell the mbed to turn off all of the shiftbrite lights. To control the brightness of the individual lights of the shiftbrite you send the first letter of the color then space then the brightness ranging from 0 to 9 with 0 being off and 9 being the brightest. So for example "r 5" will turn red on half brightness, "b 0" will turn blue off, and "g 9" will turn green on the maximum brightness. The only 3 colors on the shiftbrite are red, blue, and green.
Troubleshooting
The main problem we encountered and think should be taken into consideration when using the websocket server to send commands is that the commands are read in as ascii characters. So when switching from char to int, float, or any other numeral they will be the numerical ascii values not the numerical values you put in the webserver. We overcame this by implementing the conversion in the LED function. If taking in more robust commands a more robust solution than ours may be needed.
Parts
- ShiftBrite
- HMC6352 Digital Compass
- Ethernet RJ45 Jack
Library
Make Sure to change the Websocket server URL to your websocket server URL.
Import programwebsocketexample
Using a websocket to control a ShiftBrite LED and a digital compass
Code
Make Sure to change the Websocket server URL to your websocket server URL.
Pin Layout
HMC6352 | mbed | Ethernet | mbed | ShiftBrite | mbed | ||
---|---|---|---|---|---|---|---|
Vcc | Vout | TD+ | P1 | Gnd | Gnd | ||
Gnd | Gnd | TD- | P2 | DI | p11 | ||
SCL | SDA | RD+ | P7 | LI | p15 | ||
RD- | P8 | EI | p16 | ||||
CI | p13 | ||||||
V+* | VU(5V) |
Picture
Video
References
These are the pages that we used to get the Instructions on how to interface the components with the mbed as well as the related api's.
Please log in to post comments.