Hello,
I have a problem related to the bluetooth shield of seeedstudio, especially the code. (The project contains 80 LEDs, they work fine and i'm using an uno board).
I've already written something to send data via USB/serial port with the following code:
//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
////Pin connected to DS of 74HC595
int dataPin = 11;
String inputString = "";
boolean stringComplete = false;
byte dataEen;
byte dataTwee;
byte dataDrie;
byte dataVier;
byte dataVijf;
byte dataZes;
byte dataZeven;
byte dataAcht;
byte dataNegen;
byte dataTien;
char dataArray[10];
char *dataFinalArray[4];
void setup() {
Serial.begin(115200);
pinMode(latchPin, OUTPUT);
inputString.reserve(200);
}
void loop()
{
if (stringComplete) {
Serial.print(inputString);
// clear the string:
char filename[80];
inputString.toCharArray(filename,80);
char *p = filename;
char *str;
int i = 0;
while ((str = strtok_r(p, ";", &p)) != NULL)
{
dataFinalArray[i] = str;
i++;
}
inputString = "";
stringComplete = false;
dataEen = atoi(dataFinalArray[0]);
dataTwee = atoi(dataFinalArray[1]);
dataDrie = atoi(dataFinalArray[2]);
dataVier = atoi(dataFinalArray[3]);
dataVijf = atoi(dataFinalArray[4]);
dataZes = atoi(dataFinalArray[5]);
dataZeven = atoi(dataFinalArray[6]);
dataAcht = atoi(dataFinalArray[7]);
dataNegen = atoi(dataFinalArray[8]);
dataTien = atoi(dataFinalArray[9]);
digitalWrite(latchPin, 0);
shiftOut(dataPin, clockPin, dataEen);
shiftOut(dataPin, clockPin, dataTwee);
shiftOut(dataPin, clockPin, dataDrie);
shiftOut(dataPin, clockPin, dataVier);
shiftOut(dataPin, clockPin, dataVijf);
shiftOut(dataPin, clockPin, dataZes);
shiftOut(dataPin, clockPin, dataZeven);
shiftOut(dataPin, clockPin, dataAcht);
shiftOut(dataPin, clockPin, dataNegen);
shiftOut(dataPin, clockPin, dataTien);
digitalWrite(latchPin, 1);
}
}
void serialEvent() {
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
Serial.print(inChar);
if (inChar == '\n') {
stringComplete = true;
}
else
{
inputString += inChar;
}
}
}
void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
int i=0;
int pinState;
pinMode(myClockPin, OUTPUT);
pinMode(myDataPin, OUTPUT);
digitalWrite(myDataPin, 0);
digitalWrite(myClockPin, 0);
for (i=7; i>=0; i--) {
digitalWrite(myClockPin, 0);
if ( myDataOut & (1<<i) ) {
pinState= 1;
}
else {
pinState= 0;
}
digitalWrite(myDataPin, pinState);
digitalWrite(myClockPin, 1);
digitalWrite(myDataPin, 0);
}
digitalWrite(myClockPin, 0);
}
If you look at the example to make your bluetooth shield a Slave you will see that there is no bluetoothEvent() such as serialEvent() to control the incomming data.
This has been resolved with the bluetooth serial in the void loop stabbing.
The fact is that I need my void loop to split the data and send to the shiftOut.
But i cannot get it right. This is the code i already tried: (built further on the Slave example)
/*
BluetoothShield Demo Code Slave.pde. This sketch could be used with
Master.pde to establish connection between two Arduino. It can also
be used for one slave bluetooth connected by the device(PC/Smart Phone)
with bluetooth function.
2011 Copyright (c) Seeed Technology Inc. All right reserved.
Author: Steve Chang
This demo code is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
For more details about the product please check http://www.seeedstudio.com/depot/
*/
/* Upload this sketch into Seeeduino and press reset*/
#include <SoftwareSerial.h> //Software Serial Port
#define RxD 6
#define TxD 7
#define DEBUG_ENABLED 1
SoftwareSerial blueToothSerial(RxD,TxD);
//VARS
//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
////Pin connected to DS of 74HC595
int dataPin = 11;
String inputString = "";
boolean stringComplete = false;
byte dataEen;
byte dataTwee;
byte dataDrie;
byte dataVier;
byte dataVijf;
byte dataZes;
byte dataZeven;
byte dataAcht;
byte dataNegen;
byte dataTien;
char dataArray[10];
char *dataFinalArray[4];
void setup() {
Serial.begin(38400);
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
pinMode(latchPin, OUTPUT);
Serial.println("HELLO");
setupBlueToothConnection();
inputString.reserve(200);
}
void loop() {
//while(1){
if(blueToothSerial.available()){//check if there's any data sent from the remote bluetooth shield
char inChar = (char)blueToothSerial.read();
Serial.print(inChar);
if(inChar =='\n'){
stringComplete = true;
}else{
inputString +=inChar;
}
}
//}
if(stringComplete == true){
Serial.print("inChar");
char filename[80];
inputString.toCharArray(filename,80);
char *p = filename;
char *str;
int i = 0;
while ((str = strtok_r(p, ";", &p)) != NULL)
{
dataFinalArray[i] = str;
i++;
}
inputString = "";
dataEen = atoi(dataFinalArray[0]);
dataTwee = atoi(dataFinalArray[1]);
dataDrie = atoi(dataFinalArray[2]);
dataVier = atoi(dataFinalArray[3]);
dataVijf = atoi(dataFinalArray[4]);
dataZes = atoi(dataFinalArray[5]);
dataZeven = atoi(dataFinalArray[6]);
dataAcht = atoi(dataFinalArray[7]);
dataNegen = atoi(dataFinalArray[8]);
dataTien = atoi(dataFinalArray[9]);
digitalWrite(latchPin, 0);
shiftOut(dataPin, clockPin, dataEen);
shiftOut(dataPin, clockPin, dataTwee);
shiftOut(dataPin, clockPin, dataDrie);
shiftOut(dataPin, clockPin, dataVier);
shiftOut(dataPin, clockPin, dataVijf);
shiftOut(dataPin, clockPin, dataZes);
shiftOut(dataPin, clockPin, dataZeven);
shiftOut(dataPin, clockPin, dataAcht);
shiftOut(dataPin, clockPin, dataNegen);
shiftOut(dataPin, clockPin, dataTien);
digitalWrite(latchPin, 1);
}
}
void setupBlueToothConnection() {
blueToothSerial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400
blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
blueToothSerial.print("\r\n+STNA=SeeedBTSlave\r\n"); //set the bluetooth name as "SeeedBTSlave"
blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
delay(2000); // This delay is required.
blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable
Serial.println("The slave bluetooth is inquirable!");
delay(2000); // This delay is required.
blueToothSerial.flush();
}
void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
int i=0;
int pinState;
pinMode(myClockPin, OUTPUT);
pinMode(myDataPin, OUTPUT);
digitalWrite(myDataPin, 0);
digitalWrite(myClockPin, 0);
for (i=7; i>=0; i--) {
digitalWrite(myClockPin, 0);
if ( myDataOut & (1<<i) ) {
pinState= 1;
}
else {
pinState= 0;
}
digitalWrite(myDataPin, pinState);
digitalWrite(myClockPin, 1);
digitalWrite(myDataPin, 0);
}
digitalWrite(myClockPin, 0);
}
Could someone help me to obtain the same result as the USB connection?
Best regards Luc