You are viewing an older revision! See the latest version
Project
Introduction¶
In this project we have tried to emulate one of the demo programs in Psoc starter kit using mbed chips. For wireless transmission of text , we have used 2 zigbee modules(1 transmitter and 2nd receiver).
In the first part , the data which is transmitted is displayed using red leds and accelerometer . When moving the breadboard fast which has the receiver zigbee module , 8 red leds and the accelerometer , we are able to successfully display the text using persistence of vision property. We displayed around 14 characters.
In the Second part, we have displayed the transmitted text using shiftbrite registers using the same technique as used for LED's. In this part we could only display maximum of 4-5 letters , Numbers(0-9) or Special characters.
The last thing which we have implemented is we displayed a Bitmap image on the shiftbrite registers. The bitmap image was first processed in Matlab and the co-ordinates were included in the source code. We successfully implemented some images like circle, square etc.
Block Diagram¶


Hardware Used¶
- 2 mbed chip LPC 1768
- 2 Xbee module [1 transmitter and 1 receiver]
- Accelerometer
- 8 Shiftbrite register
- 8 Red LED's and resistors
Connections¶
Receiver Side¶
| Acceleromter | MBED | Xbee | Shiftbrite |
| Vout | vcc | ||
| P10 | Dout | ||
| P9 | Din | ||
| P17 | RST | ||
| GND | GND | GND | GND |
| VCC | VU | VCC | |
| SDA | P5 | ||
| SDO | P6 | ||
| CLK | P7 | ||
| CS | P8 | ||
| P11 | DI | ||
| P13 | CI | ||
| P15 | LI | ||
| P16 | EI |
Transmitting Side¶
| MBED | Xbee |
| Vout | vcc |
| P10 | Dout |
| P9 | Din |
| P11 | RST |
| GND | GND |
Source Code¶
Trasmitter Code
- Note the transmitter ZigBee code remains the same for Part1 and Part2. In Part3 , we are not transmitting the bitmap Image*
Transmission using ZigBee¶
/// SENDER ZIGBEE
#include "mbed.h"
#include "iostream"
#include "stdio.h"
#include "stdlib.h"
using namespace std;
Serial pc(USBTX, USBRX);
Serial xbee1(p9,p10);
DigitalOut rst1(p11); //Digital reset for the XBee, 200ns for reset
DigitalOut myled(LED1);//Create variable for Led 3 on the mbed
int main()
{
int character;
char buffer[20];
rst1 = 0; //Set reset pin to 0
myled = 0;//Set LED3 to 0
wait_ms(1);//Wait at least one millisecond
rst1 = 1;//Set reset pin to 1
wait_ms(1);//Wait another millisecond
while (1)
{
if(pc.readable()) {
//pc.gets(buffer,10);
//xbee1.putc(buffer); //XBee write whatever the PC is sending
myled = !myled;
character = pc.getc();
xbee1.putc(character);
pc.putc(character);
}
//pc.printf("I got %s on sending side \n", buffer);
wait(.1);
}
}
Receiver Code
1. Red LED with ZigBee¶
//Red LED with ZigBee
#include "ADXL345.h"
#include "mbed.h"
#include "iostream"
#include "stdio.h"
#include "stdlib.h"
#include "string"
using namespace std;
PortOut ledport(Port1, 0xFFFFFFFF);
ADXL345 accelerometer(p5, p6, p7, p8);
//Serial pc(USBTX, USBRX);
DigitalOut led8(p28);
DigitalOut led7(p27);
DigitalOut led6(p26);
DigitalOut led5(p25);
DigitalOut led4(p24);
DigitalOut led3(p23);
DigitalOut led2(p22);
DigitalOut led1(p21);
DigitalOut test(LED4);
// ------------------------- Zigbee -------------
Serial xbee2(p9, p10);
DigitalOut rst1(p11);
Serial pc1(USBTX, USBRX);
DigitalOut myled(LED2);
int main()
{
int count=0;
int readings[3] = {0, 0, 0};
//int del = 0;
int16_t sum = 0;
int16_t xval[50];
int i = 0;
char text[30];
int len,len1;
len1 = 0;
len = 0;
// --------- Zigbee
char character;
rst1 = 0; //Set reset pin to 0
myled = 0;
wait_ms(1);
rst1 = 1; //Set reset pin to 1
wait_ms(1);
char buffer[20];
int global = 0;
//--- Zigbeeee
const char font[0x60][5] = {
{0x00,0x00,0x00,0x00,0x00}, // ASCII - 32 space
{0x00,0x00,0xF9,0x00,0x00}, // ASCII - 33 !
{0x00,0xE0,0x00,0xE0,0x00}, // ASCII - 34 "
{0x24,0x7E,0x24,0x7E,0x24}, // ASCII - 35 #
{0x34,0x4A,0xFF,0x49,0x26}, // ASCII - 36 $
{0x22,0x04,0x08,0x10,0x22}, // ASCII - 37 %
{0x26,0x59,0x4D,0x52,0x25}, // ASCII - 38 &
{0x00,0x00,0xE0,0x00,0x00}, // ASCII - 39 '
{0x00,0x3C,0x42,0x81,0x00}, // ASCII - 40 (
{0x00,0x81,0x42,0x3C,0x00}, // ASCII - 41 )
{0x28,0x30,0xE0,0x30,0x28}, // ASCII - 42 *
{0x08,0x08,0x3E,0x08,0x08}, // ASCII - 43 +
{0x00,0x01,0x02,0x00,0x00}, // ASCII - 44 ,
{0x08,0x08,0x08,0x08,0x08}, // ASCII - 45 -
{0x00,0x00,0x01,0x00,0x00}, // ASCII - 46 .
{0x02,0x04,0x08,0x10,0x20}, // ASCII - 47 /
{0x7E,0x81,0x81,0x81,0x7E}, // ASCII - 48 0
{0x00,0x21,0xFF,0x01,0x00}, // ASCII - 49 1
{0x41,0x83,0x85,0x89,0x71}, // ASCII - 50 2
{0x42,0x91,0x91,0x91,0x6E}, // ASCII - 51 3
{0xF0,0x10,0x10,0x10,0xFF}, // ASCII - 52 4
{0xF2,0x91,0x91,0x91,0x8E}, // ASCII - 53 5
{0x3E,0x51,0x91,0x91,0x8E}, // ASCII - 54 6
{0x87,0x88,0x90,0xA0,0xC0}, // ASCII - 55 7
{0x76,0x89,0x89,0x89,0x76}, // ASCII - 56 8
{0x62,0x91,0x91,0x91,0x7e}, // ASCII - 57 9
{0x00,0x00,0x24,0x00,0x00}, // ASCII - 58 :
{0x00,0x01,0x12,0x00,0x00}, // ASCII - 59 ;
{0x00,0x08,0x14,0x22,0x41}, // ASCII - 60 <
{0x14,0x14,0x14,0x14,0x14}, // ASCII - 61 =
{0x00,0x41,0x22,0x14,0x08}, // ASCII - 62 >
{0x40,0x80,0x8D,0x90,0x60}, // ASCII - 63 ?
{0x7E,0x81,0xBD,0xA5,0x78}, // ASCII - 64 @
{0x3F,0x48,0x88,0x48,0x3F}, // ASCII - 65 A
{0xFF,0x91,0x91,0x99,0x66}, // ASCII - 66 B
{0x3C,0x42,0x81,0x81,0x42}, // ASCII - 67 C
{0xFF,0x81,0x81,0x42,0x3C}, // ASCII - 68 D
{0xFF,0x91,0x91,0x91,0x81}, // ASCII - 69 E
{0xFF,0x90,0x90,0x90,0x80}, // ASCII - 70 F
{0x3E,0x41,0x8F,0x88,0x4F}, // ASCII - 71 G
{0xFF,0x10,0x10,0x10,0xFF}, // ASCII - 72 H
{0x00,0x81,0xFF,0x81,0x00}, // ASCII - 73 I
{0x06,0x01,0x81,0xFE,0x80}, // ASCII - 74 J
{0xFF,0x18,0x24,0x42,0x81}, // ASCII - 75 K
{0xFF,0x01,0x01,0x01,0x01}, // ASCII - 76 L
{0xFF,0x40,0x30,0x40,0xFF}, // ASCII - 77 M
{0xFF,0x40,0x20,0x10,0xFF}, // ASCII - 78 N
{0x7E,0x81,0x81,0x81,0x7E}, // ASCII - 79 O
{0xFF,0x90,0x90,0x90,0x60}, // ASCII - 80 P
{0x7E,0x81,0x85,0x82,0x7D}, // ASCII - 81 Q
{0xFF,0x98,0x94,0x92,0x61}, // ASCII - 82 R
{0x72,0x89,0x89,0x89,0x46}, // ASCII - 83 S
{0x80,0x80,0xFF,0x80,0x80}, // ASCII - 84 T
{0xFE,0x01,0x01,0x01,0xFE}, // ASCII - 85 U
{0xFC,0x02,0x01,0x02,0xFC}, // ASCII - 86 V
{0xFF,0x02,0x1C,0x02,0xFF}, // ASCII - 87 W
{0xC3,0x24,0x18,0x24,0xC3}, // ASCII - 88 X
{0xC0,0x20,0x1F,0x20,0xC0}, // ASCII - 89 Y
{0x87,0x89,0x91,0xA1,0xC1}, // ASCII - 90 Z
{0x00,0xFF,0x81,0x81,0x00}, // ASCII - 91 [
{0x20,0x10,0x08,0x04,0x02}, // ASCII - 92 '\'
{0x00,0x81,0x81,0xFF,0x00}, // ASCII - 93 ]
{0x20,0x40,0x80,0x40,0x20}, // ASCII - 94 ^
{0x01,0x01,0x01,0x01,0x01}, // ASCII - 95 _
{0x00,0x80,0x40,0x20,0x00}, // ASCII - 96 `
{0x26,0x29,0x29,0x1F,0x01}, // ASCII - 97 a
{0xFF,0x11,0x11,0x11,0x0E}, // ASCII - 98 b
{0x0E,0x11,0x11,0x11,0x11}, // ASCII - 99 c
{0x0E,0x11,0x11,0x11,0xFF}, // ASCII - 100 d
{0x0E,0x15,0x15,0x15,0x0D}, // ASCII - 101 e
{0x10,0x10,0x7F,0x90,0x90}, // ASCII - 102 f
{0x08,0x15,0x15,0x15,0x0E}, // ASCII - 103 g
{0xFF,0x08,0x08,0x08,0x07}, // ASCII - 104 h
{0x00,0x00,0x9F,0x00,0x00}, // ASCII - 105 i
{0x02,0x01,0x01,0x9F,0x00}, // ASCII - 106 j
{0xFF,0x04,0x0A,0x11,0x00}, // ASCII - 107 k
{0x00,0x01,0xFF,0x01,0x00}, // ASCII - 108 l
{0x1F,0x10,0x0F,0x10,0x0F}, // ASCII - 109 m
{0x10,0x0F,0x10,0x10,0x0F}, // ASCII - 110 n
{0x0E,0x11,0x11,0x11,0x0E}, // ASCII - 111 o
{0x1F,0x14,0x14,0x14,0x08}, // ASCII - 112 p
{0x08,0x14,0x14,0x14,0x1F}, // ASCII - 113 q
{0x1F,0x08,0x10,0x10,0x08}, // ASCII - 114 r
{0x09,0x15,0x15,0x15,0x12}, // ASCII - 115 s
{0x10,0x10,0x7F,0x11,0x12}, // ASCII - 116 t
{0x1F,0x01,0x01,0x1F,0x01}, // ASCII - 117 u
{0x1C,0x02,0x01,0x02,0x1C}, // ASCII - 118 v
{0x1E,0x01,0x0F,0x01,0x1E}, // ASCII - 119 w
{0x11,0x0A,0x04,0x0A,0x11}, // ASCII - 120 x
{0x11,0x0A,0x04,0x08,0x10}, // ASCII - 121 y
{0x11,0x13,0x15,0x19,0x11}, // ASCII - 122 z
{0x18,0x66,0x81,0x81,0x00}, // ASCII - 123 {
{0x00,0x00,0xFF,0x00,0x00}, // ASCII - 124 |
{0x00,0x81,0x81,0x66,0x18}, // ASCII - 125 }
{0x0C,0x10,0x08,0x04,0x18}, // ASCII - 126 ~
};
char currentchar = 0;
int LED_MASK = 0xFFFFFFFF;
//pc.printf("Starting ADXL345 test...\r\n");
// pc.printf("Device ID is: 0x%02x\r\n", accelerometer.getDevId());
wait(3);
//Go into standby mode to configure the device.
accelerometer.setPowerControl(0x00);
//Full resolution, +/-16g, 4mg/LSB.
accelerometer.setDataFormatControl(0x0B);
//3.2kHz data rate.
accelerometer.setDataRate(ADXL345_3200HZ);
//Measurement mode.
accelerometer.setPowerControl(0x08);
while (1) {
global=0;
while(1) {
test = xbee2.readable();
if(xbee2.readable()) {
character = xbee2.getc();
if(character == 13) {
buffer[global] = '\0';
//strcpy(text1,buffer);
break;
} else {
buffer[global]= character;
global++;
//pc1.printf("%d" ,xbee2.readable());
}
}
}
pc1.printf("\n\rbuffer = %s\n\r" ,buffer);
//pc1.printf(" \n\rBuffer = %s", buffer);
len1 = strlen(buffer);
for( int m =0; m < (len1 + 2); m++) {
text[m] = 0x20;
}
for( int m =(len1 + 2); m <( 2*len1 + 2); m++) {
text[m] = buffer[m - (len1 +2)];
}
text[2*len1 + 2] = '\0';
len = strlen(text);
for(int p =0; p <len; p++)
{pc1.printf("%c", text[p]);
}
pc1.printf("\n\rstrlen(text) = %d", len);
float waitvalue = 0.08 / ((6*len));
while(!(xbee2.readable())) {
do {
accelerometer.getOutput(readings);
if(xbee2.readable())
break;
} while((int16_t)readings[1] < 50);
i = 0;
while(text[i] != '\0') {
led8 = 0;
led7 = 0;
led6 = 0;
led5 = 0;
led4 = 0;
led3 = 0;
led2 = 0;
led1 = 0;
wait(waitvalue);
currentchar = text[i];
for( int m =0; m <5; m++) {
char mal = font[currentchar - 0x20][m];
led8 = mal & 0x80;
led7 = mal & 0x40;
led6 = mal & 0x20;
led5 = mal & 0x10;
led4 = mal & 0x08;
led3 = mal & 0x04;
led2 = mal & 0x02;
led1 = mal & 0x01;
wait(waitvalue);
}
led8 = 0;
led7 = 0;
led6 = 0;
led5 = 0;
led4 = 0;
led3 = 0;
led2 = 0;
led1 = 0;
wait(waitvalue);
i++;
}
do {
accelerometer.getOutput(readings);
if(xbee2.readable())
break;
} while((int16_t)readings[1] > -50);
}
}
}
2. SHiftbrite with ZigBee¶
// Shiftbrite with ZigBee
#include "ADXL345.h"
#include "mbed.h"
#include "iostream"
#include "stdio.h"
#include "stdlib.h"
#include "string"
using namespace std;
PortOut ledport(Port1, 0xFFFFFFFF);
ADXL345 accelerometer(p5, p6, p7, p8);
//Serial pc(USBTX, USBRX);
//---shiftbrite
DigitalOut latch(p15);
DigitalOut enable(p16);
SPI spi(p11, p12, p13);
DigitalOut led8(p28);
DigitalOut led7(p27);
DigitalOut led6(p26);
DigitalOut led5(p25);
DigitalOut led4(p24);
DigitalOut led3(p23);
DigitalOut led2(p22);
DigitalOut led1(p21);
// ------------------------- Zigbee -------------
Serial xbee2(p9, p10);
DigitalOut rst1(p17);
Serial pc1(USBTX, USBRX);
DigitalOut myled(LED2);
//----RGB Led function
void RGB_LED(int red, int green, int blue)
{
unsigned int low_color=0;
unsigned int high_color=0;
high_color=(blue<<4)|((red&0x3C0)>>6);
low_color=(((red&0x3F)<<10)|(green));
spi.write(high_color);
spi.write(low_color);
latch=1;
latch=0;
}
int main()
{
int count=0;
int readings[3] = {0, 0, 0};
//int del = 0;
int16_t sum = 0;
int16_t xval[50];
int i = 0;
char text[30];
int len,len1;
len1 = 0;
len = 0;
//---------SHift brite
int red=0;
int green=0;
int blue=0;
spi.format(16,0);
spi.frequency(500000);
enable=0;
latch=0;
// --------- Zigbee
char character;
rst1 = 0; //Set reset pin to 0
myled = 0;
wait_ms(1);
rst1 = 1; //Set reset pin to 1
wait_ms(1);
char buffer[20];
int global = 0;
//--- Zigbeeee
const char font[0x60][5] = {
{0x00,0x00,0x00,0x00,0x00}, // ASCII - 32 space
{0x00,0x00,0xF9,0x00,0x00}, // ASCII - 33 !
{0x00,0xE0,0x00,0xE0,0x00}, // ASCII - 34 "
{0x24,0x7E,0x24,0x7E,0x24}, // ASCII - 35 #
{0x34,0x4A,0xFF,0x49,0x26}, // ASCII - 36 $
{0x22,0x04,0x08,0x10,0x22}, // ASCII - 37 %
{0x26,0x59,0x4D,0x52,0x25}, // ASCII - 38 &
{0x00,0x00,0xE0,0x00,0x00}, // ASCII - 39 '
{0x00,0x3C,0x42,0x81,0x00}, // ASCII - 40 (
{0x00,0x81,0x42,0x3C,0x00}, // ASCII - 41 )
{0x28,0x30,0xE0,0x30,0x28}, // ASCII - 42 *
{0x08,0x08,0x3E,0x08,0x08}, // ASCII - 43 +
{0x00,0x01,0x02,0x00,0x00}, // ASCII - 44 ,
{0x08,0x08,0x08,0x08,0x08}, // ASCII - 45 -
{0x00,0x00,0x01,0x00,0x00}, // ASCII - 46 .
{0x02,0x04,0x08,0x10,0x20}, // ASCII - 47 /
{0x7E,0x81,0x81,0x81,0x7E}, // ASCII - 48 0
{0x00,0x21,0xFF,0x01,0x00}, // ASCII - 49 1
{0x41,0x83,0x85,0x89,0x71}, // ASCII - 50 2
{0x42,0x91,0x91,0x91,0x6E}, // ASCII - 51 3
{0xF0,0x10,0x10,0x10,0xFF}, // ASCII - 52 4
{0xF2,0x91,0x91,0x91,0x8E}, // ASCII - 53 5
{0x3E,0x51,0x91,0x91,0x8E}, // ASCII - 54 6
{0x87,0x88,0x90,0xA0,0xC0}, // ASCII - 55 7
{0x76,0x89,0x89,0x89,0x76}, // ASCII - 56 8
{0x62,0x91,0x91,0x91,0x7e}, // ASCII - 57 9
{0x00,0x00,0x24,0x00,0x00}, // ASCII - 58 :
{0x00,0x01,0x12,0x00,0x00}, // ASCII - 59 ;
{0x00,0x08,0x14,0x22,0x41}, // ASCII - 60 <
{0x14,0x14,0x14,0x14,0x14}, // ASCII - 61 =
{0x00,0x41,0x22,0x14,0x08}, // ASCII - 62 >
{0x40,0x80,0x8D,0x90,0x60}, // ASCII - 63 ?
{0x7E,0x81,0xBD,0xA5,0x78}, // ASCII - 64 @
{0x3F,0x48,0x88,0x48,0x3F}, // ASCII - 65 A
{0xFF,0x91,0x91,0x99,0x66}, // ASCII - 66 B
{0x3C,0x42,0x81,0x81,0x42}, // ASCII - 67 C
{0xFF,0x81,0x81,0x42,0x3C}, // ASCII - 68 D
{0xFF,0x91,0x91,0x91,0x81}, // ASCII - 69 E
{0xFF,0x90,0x90,0x90,0x80}, // ASCII - 70 F
{0x3E,0x41,0x8F,0x88,0x4F}, // ASCII - 71 G
{0xFF,0x10,0x10,0x10,0xFF}, // ASCII - 72 H
{0x00,0x81,0xFF,0x81,0x00}, // ASCII - 73 I
{0x06,0x01,0x81,0xFE,0x80}, // ASCII - 74 J
{0xFF,0x18,0x24,0x42,0x81}, // ASCII - 75 K
{0xFF,0x01,0x01,0x01,0x01}, // ASCII - 76 L
{0xFF,0x40,0x30,0x40,0xFF}, // ASCII - 77 M
{0xFF,0x40,0x20,0x10,0xFF}, // ASCII - 78 N
{0x7E,0x81,0x81,0x81,0x7E}, // ASCII - 79 O
{0xFF,0x90,0x90,0x90,0x60}, // ASCII - 80 P
{0x7E,0x81,0x85,0x82,0x7D}, // ASCII - 81 Q
{0xFF,0x98,0x94,0x92,0x61}, // ASCII - 82 R
{0x72,0x89,0x89,0x89,0x46}, // ASCII - 83 S
{0x80,0x80,0xFF,0x80,0x80}, // ASCII - 84 T
{0xFE,0x01,0x01,0x01,0xFE}, // ASCII - 85 U
{0xFC,0x02,0x01,0x02,0xFC}, // ASCII - 86 V
{0xFF,0x02,0x1C,0x02,0xFF}, // ASCII - 87 W
{0xC3,0x24,0x18,0x24,0xC3}, // ASCII - 88 X
{0xC0,0x20,0x1F,0x20,0xC0}, // ASCII - 89 Y
{0x87,0x89,0x91,0xA1,0xC1}, // ASCII - 90 Z
{0x00,0xFF,0x81,0x81,0x00}, // ASCII - 91 [
{0x20,0x10,0x08,0x04,0x02}, // ASCII - 92 '\'
{0x00,0x81,0x81,0xFF,0x00}, // ASCII - 93 ]
{0x20,0x40,0x80,0x40,0x20}, // ASCII - 94 ^
{0x01,0x01,0x01,0x01,0x01}, // ASCII - 95 _
{0x00,0x80,0x40,0x20,0x00}, // ASCII - 96 `
{0x26,0x29,0x29,0x1F,0x01}, // ASCII - 97 a
{0xFF,0x11,0x11,0x11,0x0E}, // ASCII - 98 b
{0x0E,0x11,0x11,0x11,0x11}, // ASCII - 99 c
{0x0E,0x11,0x11,0x11,0xFF}, // ASCII - 500 d
{0x0E,0x15,0x15,0x15,0x0D}, // ASCII - 101 e
{0x10,0x10,0x7F,0x90,0x90}, // ASCII - 102 f
{0x08,0x15,0x15,0x15,0x0E}, // ASCII - 103 g
{0xFF,0x08,0x08,0x08,0x07}, // ASCII - 104 h
{0x00,0x00,0x9F,0x00,0x00}, // ASCII - 105 i
{0x02,0x01,0x01,0x9F,0x00}, // ASCII - 106 j
{0xFF,0x04,0x0A,0x11,0x00}, // ASCII - 107 k
{0x00,0x01,0xFF,0x01,0x00}, // ASCII - 108 l
{0x1F,0x10,0x0F,0x10,0x0F}, // ASCII - 109 m
{0x10,0x0F,0x10,0x10,0x0F}, // ASCII - 110 n
{0x0E,0x11,0x11,0x11,0x0E}, // ASCII - 111 o
{0x1F,0x14,0x14,0x14,0x08}, // ASCII - 112 p
{0x08,0x14,0x14,0x14,0x1F}, // ASCII - 113 q
{0x1F,0x08,0x10,0x10,0x08}, // ASCII - 114 r
{0x09,0x15,0x15,0x15,0x12}, // ASCII - 115 s
{0x10,0x10,0x7F,0x11,0x12}, // ASCII - 116 t
{0x1F,0x01,0x01,0x1F,0x01}, // ASCII - 117 u
{0x1C,0x02,0x01,0x02,0x1C}, // ASCII - 118 v
{0x1E,0x01,0x0F,0x01,0x1E}, // ASCII - 119 w
{0x11,0x0A,0x04,0x0A,0x11}, // ASCII - 120 x
{0x11,0x0A,0x04,0x08,0x10}, // ASCII - 121 y
{0x11,0x13,0x15,0x19,0x11}, // ASCII - 122 z
{0x18,0x66,0x81,0x81,0x00}, // ASCII - 123 {
{0x00,0x00,0xFF,0x00,0x00}, // ASCII - 124 |
{0x00,0x81,0x81,0x66,0x18}, // ASCII - 125 }
{0x0C,0x10,0x08,0x04,0x18}, // ASCII - 126 ~
};
char currentchar = 0;
int LED_MASK = 0xFFFFFFFF;
//pc.printf("Starting ADXL345 test...\r\n");
// pc.printf("Device ID is: 0x%02x\r\n", accelerometer.getDevId());
wait(3);
//Go into standby mode to configure the device.
accelerometer.setPowerControl(0x00);
//Full resolution, +/-16g, 4mg/LSB.
accelerometer.setDataFormatControl(0x0B);
//3.2kHz data rate.
accelerometer.setDataRate(ADXL345_3200HZ);
//Measurement mode.
accelerometer.setPowerControl(0x08);
while (1) {
global=0;
while(1) {
// test = xbee2.readable();
if(xbee2.readable()) {
character = xbee2.getc();
if(character == 13) {
buffer[global] = '\0';
break;
} else {
buffer[global]= character;
global++;
}
}
}
pc1.printf("\n\rbuffer = %s\n\r" ,buffer);
//pc1.printf(" \n\rBuffer = %s", buffer);
len1 = strlen(buffer);
for( int m =0; m < (len1 + 2); m++) {
text[m] = 0x20;
}
for( int m =(len1 + 2); m <( 2*len1 + 2); m++) {
text[m] = buffer[m - (len1 +2)];
}
text[2*len1 + 2] = '\0';
len = strlen(text);
for(int p =0; p <len; p++) {
pc1.printf("%c", text[p]);
}
pc1.printf("\n\rstrlen(text) = %d", len);
float waitvalue = 0.08 / ((6*len));
while(!(xbee2.readable())) {
red = 0;
green = 0;
blue = 0;
do {
accelerometer.getOutput(readings);
if(xbee2.readable())
break;
} while((int16_t)readings[1] < 50);
i = 0;
while(text[i] != '\0') {
/*led8 = 0;
led7 = 0;
led6 = 0;
led5 = 0;
led4 = 0;
led3 = 0;
led2 = 0;
led1 = 0;*/
for( int m=0; m < 8; m++) {
red = 0;
green = 0;
blue = 0;
RGB_LED(red,green,blue);
}
wait(waitvalue);
currentchar = text[i];
for( int m =0; m <5; m++) {
char mal = font[currentchar - 0x20][m];
led8 = mal & 0x80;
led7 = mal & 0x40;
led6 = mal & 0x20;
led5 = mal & 0x10;
led4 = mal & 0x08;
led3 = mal & 0x04;
led2 = mal & 0x02;
led1 = mal & 0x01;
if(led8 == 1) {
green = 0;
red = 500;
blue = 0;
RGB_LED(red,green,blue);
} else {
red = 0;
green = 0;
blue = 0;
RGB_LED(red,green,blue);
}
if(led7 == 1) {
green = 0;
red = 500;
blue = 0;
RGB_LED(red,green,blue);
} else {
red = 0;
green = 0;
blue = 0;
RGB_LED(red,green,blue);
}
if(led6 == 1) {
green = 0;
red = 500;
blue = 0;
RGB_LED(red,green,blue);
} else {
red = 0;
green = 0;
blue = 0;
RGB_LED(red,green,blue);
}
if(led5 == 1) {
green = 500;
red = 0;
blue = 0;
RGB_LED(red,green,blue);
} else {
red = 0;
green = 0;
blue = 0;
RGB_LED(red,green,blue);
}
if(led4 == 1) {
green = 500;
red = 0;
blue = 0;
RGB_LED(red,green,blue);
} else {
red = 0;
green = 0;
blue = 0;
RGB_LED(red,green,blue);
}
if(led3 == 1) {
green = 500;
red = 0;
blue = 0;
RGB_LED(red,green,blue);
} else {
red = 0;
green = 0;
blue = 0;
RGB_LED(red,green,blue);
}
if(led2 == 1) {
green = 0;
red = 0;
blue = 500;
RGB_LED(red,green,blue);
} else {
red = 0;
green = 0;
blue = 0;
RGB_LED(red,green,blue);
}
if(led1 == 1) {
green = 0;
red = 0;
blue = 500;
RGB_LED(red,green,blue);
} else {
red = 0;
green = 0;
blue = 0;
RGB_LED(red,green,blue);
}
wait(waitvalue);
}
/*led8 = 0;
led7 = 0;
led6 = 0;
led5 = 0;
led4 = 0;
led3 = 0;
led2 = 0;
led1 = 0;*/
for( int j=0; j< 8; j++) {
red = 0;
green = 0;
blue = 0;
RGB_LED(red,green,blue);
}
wait(waitvalue);
i++;
}
do {
accelerometer.getOutput(readings);
if(xbee2.readable())
break;
} while((int16_t)readings[1] > -50);
}
}
}
3. Shiftbrite with circle image(no ZigBee)¶
//Shiftbrite with circle image(no ZigBee)
#include "ADXL345.h"
#include "mbed.h"
DigitalOut latch(p15);
DigitalOut enable(p16);
DigitalIn s1(p29);
DigitalIn s2(p30);
//Cycles through different colors on RGB LED
SPI spi(p11, p12, p13);
//Use SPI hardware to write color values to LED driver chip
PortOut ledport(Port1, 0xFFFFFFFF);
ADXL345 accelerometer(p5, p6, p7, p8);
//Serial pc(USBTX, USBRX);
DigitalOut led8(p28);
DigitalOut led7(p27);
DigitalOut led6(p26);
DigitalOut led5(p25);
DigitalOut led4(p24);
DigitalOut led3(p23);
DigitalOut led2(p22);
DigitalOut led1(p21);
// ------------------------- Zigbee -------------
Serial pc1(USBTX, USBRX);
const int redcolor[10][8]={
{255 , 250, 0, 0 , 0, 0, 244, 255},
{251, 0, 0, 219 ,225 , 0 , 0 ,244},
{ 0 , 0 ,255 , 255, 255 , 255 , 0 , 0},
{0 , 222, 255, 254, 254, 255, 242 , 0},
{0 , 252 , 254 , 254 , 254 , 254 , 255, 0},
{0 , 254 ,254 , 254 , 254 , 254 , 255 , 0},
{0 , 230 ,255 , 254, 254, 255, 246, 0},
{0 , 0 , 255 , 255 , 255 , 255, 0, 0},
{244 , 0 , 0 , 244 , 250 , 0 , 0 ,232},
{255 , 238 , 0 , 0 , 0 , 0 , 227 , 255}
};
const int greencolor[10][8] = {
{255, 250 , 0 , 0 , 0 , 0 , 244 , 255},
{251 , 0 , 0 , 219 ,217 , 0 , 0 , 244},
{ 0 , 0 ,253 , 254, 245 , 255 , 0, 0},
{0 , 212 , 246 ,254 , 242 , 244 ,230 , 0},
{0 , 240 , 242 , 254 ,242 , 242 , 249 , 0},
{0 , 241 , 242 , 254 , 242, 242 , 250, 0},
{0 ,220 , 245 , 255 , 242 , 243, 235 , 0},
{0 , 0 , 255 , 255 , 243 , 255 , 0 , 0},
{ 244 , 0 , 0 , 244 ,242 , 0 , 0 , 232},
{ 255 , 238 , 0 , 0 , 0 , 0 , 228, 255}
};
const int bluecolor[10][8]= {
{255 , 251 ,0, 0 , 0 , 0, 246, 255},
{253 , 0 , 0 , 0 , 0 , 0 , 0 , 247},
{ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0},
{0 , 0 , 0 , 0 , 0 , 0 , 0 , 0},
{0 , 0 , 0 , 0 , 0 , 0, 0 , 0},
{0 , 0 , 0 , 0 , 0 , 0 , 0 , 0},
{0 , 0 , 0 , 0 , 0 , 0 , 0 , 0},
{0 , 0 , 0 , 0 , 0 , 0 , 0 , 0},
{247 , 0 , 0 , 0 , 0 , 0 , 0, 237},
{255 , 240 , 0 , 0 , 0 , 0, 232 ,255}
};
void RGB_LED(int red, int green, int blue)
{
unsigned int low_color=0;
unsigned int high_color=0;
high_color=(blue<<4)|((red&0x3C0)>>6);
low_color=(((red&0x3F)<<10)|(green));
spi.write(high_color);
spi.write(low_color);
latch=1;
latch=0;
}
int main()
{
int readings[3] = {0, 0, 0};
int i = 0;
const char text1[50] = "HI";
int len;
char character;
char currentchar = 0;
int LED_MASK = 0xFFFFFFFF;
int red=0;
int green=0;
int blue=0;
spi.format(16,0);
spi.frequency(500000);
enable=0;
latch=0;
len = 0;
for(int n = 0; text1[n] != '\0'; n++) {
len++;
}
float waitvalue = 0.06/((6*len) + 1);
pc1.printf("text1 = %s\n\r", text1);
// pc.printf("Device ID is: 0x%02x\r\n", accelerometer.getDevId());
wait(3);
//Go into standby mode to configure the device.
accelerometer.setPowerControl(0x00);
//Full resolution, +/-16g, 4mg/LSB.
accelerometer.setDataFormatControl(0x0B);
//3.2kHz data rate.
accelerometer.setDataRate(ADXL345_3200HZ);
//Measurement mode.
accelerometer.setPowerControl(0x08);
while (1) {
red = 0;
green = 0;
blue = 0;
accelerometer.getOutput(readings);
do {
accelerometer.getOutput(readings);
pc1.printf("| 1st while reading value = %i\n\r",(int16_t)readings[1]);
} while((int16_t)readings[1] < 50);
i = 0;
//while(text1[i] != '\0')
{
/* led8 = 0;
led7 = 0;
led6 = 0;
led5 = 0;
led4 = 0;
led3 = 0;
led2 = 0;
led1 = 0; */
for( int m=0; m< 8; m++) {
red = 0;
green = 0;
blue = 0;
RGB_LED(red,green,blue);
}
wait(waitvalue);
for( int m=0; m< 8; m++) {
red = 0;
green = 0;
blue = 0;
RGB_LED(red,green,blue);
}
wait(waitvalue);
//currentchar = text1[i];
for( int m =0; m < 10; m++) {
/*char mal = font[currentchar - 0x20][m];
led8 = mal & 0x80;
led7 = mal & 0x40;
led6 = mal & 0x20;
led5 = mal & 0x10;
led4 = mal & 0x08;
led3 = mal & 0x04;
led2 = mal & 0x02;
led1 = mal & 0x01;*/
// if(led8 == 1)
green = greencolor[m][7];
red = redcolor[m][7];
blue = bluecolor[m][7];
RGB_LED(red,green,blue);
green = greencolor[m][6];
red = redcolor[m][6];
blue = bluecolor[m][6];
RGB_LED(red,green,blue);
green = greencolor[m][5];
red = redcolor[m][5];
blue = bluecolor[m][5];
RGB_LED(red,green,blue);
green = greencolor[m][4];
red = redcolor[m][4];
blue = bluecolor[m][4];
RGB_LED(red,green,blue);
green = greencolor[m][3];
red = redcolor[m][3];
blue = bluecolor[m][3];
RGB_LED(red,green,blue);
green = greencolor[m][2];
red = redcolor[m][2];
blue = bluecolor[m][2];
RGB_LED(red,green,blue);
green = greencolor[m][1];
red = redcolor[m][1];
blue = bluecolor[1][m];
RGB_LED(red,green,blue);
green = greencolor[m][0];
red = redcolor[m][0];
blue = bluecolor[m][0];
RGB_LED(red,green,blue);
wait(waitvalue);
}
/* led8 = 0;
led7 = 0;
led6 = 0;
led5 = 0;
led4 = 0;
led3 = 0;
led2 = 0;
led1 = 0; */
for( int j=0; j< 8; j++) {
red = 0;
green = 0;
blue = 0;
RGB_LED(red,green,blue);
}
wait(waitvalue);
for( int j=0; j< 8; j++) {
red = 0;
green = 0;
blue = 0;
RGB_LED(red,green,blue);
}
wait(waitvalue);
}
do {
accelerometer.getOutput(readings);
pc1.printf("| 2nd while reading value = %i\n\r",(int16_t)readings[1]);
} while((int16_t)readings[1] > -50);
}
}
Project Images¶
ZigBee Transmitter(right) and Receiver(left)

Shiftbrite module

Demo¶
Group Members¶
- Dhaval Mehta
- Jill Parekh
- Aditya Barve
- Malavika Prasanna