neopixel stick 8 e android/bluetooth

Ciao a tutti, non riesco a capire il funzionamento di questo codice

/*
PROJECT: ArduDroid
PROGRAMMER: Hazim Bitar (techbitar at gmail dot com)
DATE: Oct 31, 2013
FILE: ardudroid.ino
LICENSE: Public domain
/
#include <Adafruit_NeoPixel.h>
#define PIN 6
#define NUMPIXELS 8
#define START_CMD_CHAR '
'
#define END_CMD_CHAR '#'
#define DIV_CMD_CHAR '|'
#define CMD_DIGITALWRITE 10
#define CMD_ANALOGWRITE 11
#define CMD_TEXT 12
#define CMD_READ_ARDUDROID 13
#define MAX_COMMAND 20 // max command number code. used for error checking.
#define MIN_COMMAND 10 // minimum command number code. used for error checking.
#define IN_STRING_LENGHT 40
#define MAX_ANALOGWRITE 255
#define PIN_HIGH 3
#define PIN_LOW 2
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 500; // delay for half a second
String inText;

void setup() {
Serial.begin(9600);
Serial.println("ArduDroid 0.12 Alpha by TechBitar (2013)");
Serial.flush();
pixels.begin();
}

void loop()
{
Serial.flush();
int ard_command = 0;
int pin_num = 0;
int pin_value = 0;

char get_char = ' '; //read serial

// wait for incoming data
if (Serial.available() < 1) return; // if serial empty, return to loop().

// parse incoming command start flag
get_char = Serial.read();
if (get_char != START_CMD_CHAR) return; // if no command start flag, return to loop().

// parse incoming command type
ard_command = Serial.parseInt(); // read the command

// parse incoming pin# and value
pin_num = Serial.parseInt(); // read the pin
pin_value = Serial.parseInt(); // read the value

// 1) GET TEXT COMMAND FROM ARDUDROID
if (ard_command == CMD_TEXT){
inText =""; //clears variable for new input
while (Serial.available()) {
char c = Serial.read(); //gets one byte from serial buffer
delay(5);
if (c == END_CMD_CHAR) { // if we the complete string has been read
// add your code here
break;
}
else {
if (c != DIV_CMD_CHAR) {
inText += c;
delay(5);
}
}
}
}

// 2) GET digitalWrite DATA FROM ARDUDROID
if (ard_command == CMD_DIGITALWRITE){
if (pin_value == PIN_LOW) pin_value = LOW;
else if (pin_value == PIN_HIGH) pin_value = HIGH;
else return; // error in pin value. return.
set_digitalwrite( pin_num, pin_value); // Uncomment this function if you wish to use
return; // return from start of loop()
}

// 3) GET analogWrite DATA FROM ARDUDROID
if (ard_command == CMD_ANALOGWRITE) {
analogWrite( pin_num, pin_value );
// add your code here
return; // Done. return to loop();
}

// 4) SEND DATA TO ARDUDROID
if (ard_command == CMD_READ_ARDUDROID) {
// char send_to_android[] = "Place your text here." ;
// Serial.println(send_to_android); // Example: Sending text
Serial.print(" Analog 0 = ");
Serial.println(analogRead(A0)); // Example: Read and send Analog pin value to Arduino
return; // Done. return to loop();
}
}

// 2a) select the requested pin# for DigitalWrite action
void set_digitalwrite(int pin_num, int pin_value)
{
switch (pin_num) {
case 13:
pinMode(13, OUTPUT);
digitalWrite(13, pin_value);
// add your code here
break;
case 12:
pinMode(12, OUTPUT);
digitalWrite(12, pin_value);
// add your code here
break;
case 11:
pinMode(11, OUTPUT);
digitalWrite(11, pin_value);
// add your code here
break;

}
}

in pratica devo poter far accendere una neopixelstick8 tramite bluetooth, prima ancora però devo capire come funziona, qualcuno potrebbe spiegarmi per favore?

con il monitor seriale riesco a leggere sul telefono quello che scrivo ma non riesco a inviare nulla dal telefono..
sto usando un hc-06
c'è scritto 3.3level significa che devo alimentare a 3.3v oppure vuol dire altro?

inoltre ricevo questo errore anche se il caricamente sulla basetta è andato a buon fine
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: verification error, first mismatch at byte 0x0100
0x22 != 0x00
avrdude: verification error; content mismatch

... modifica il codice per usare altri pin (es. 10 e 11) per l'HC-06 e usa la SoftwareSerial ... :wink:

Se fai un po' di ricerche sul forum scoprirai che ci sono una infinità di post relativa a problemi con i moduli bluetooth connessi direttamente alla porta seriale (pin 0 e 1) ed inoltre ... con il modulo attaccato sulla seriale, NON puoi effettuare la programmazione!

Guglielmo

gpb01:
modifica....

eccomi di ritorno nel frattempo sono riuscito a fare funzionare tutto, per sbaglio ho invertito TX e RX e ora funziona tutto, dunque qui c'è il codice con la neopixel integrata e riesco ad accendere la striscia con il tasto 6 dal telefono ma non riesco a spegnerla inoltre non so come fare per accendere prima una striscia e poi un'altra dato che ne ho 2.. come posso fare?

/*
PROJECT: ArduDroid
PROGRAMMER: Hazim Bitar (techbitar at gmail dot com)
DATE: Oct 31, 2013
FILE: ardudroid.ino
LICENSE: Public domain
/
#include <Adafruit_NeoPixel.h>
#define PIN 6
#define NUMPIXELS 16
#define START_CMD_CHAR '
'
#define END_CMD_CHAR '#'
#define DIV_CMD_CHAR '|'
#define CMD_DIGITALWRITE 10
#define CMD_ANALOGWRITE 11
#define CMD_TEXT 12
#define CMD_READ_ARDUDROID 13
#define MAX_COMMAND 20 // max command number code. used for error checking.
#define MIN_COMMAND 10 // minimum command number code. used for error checking.
#define IN_STRING_LENGHT 40
#define MAX_ANALOGWRITE 255
#define PIN_HIGH 3
#define PIN_LOW 2
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
String inText;
int delayval = 500;

void setup() {
Serial.begin(9600);
Serial.println("ArduDroid 0.12 Alpha by TechBitar (2013)");
Serial.flush();
pixels.begin();
}

void loop()
{ Serial.flush();
int ard_command = 0;
int pin_num = 0;
int pin_value = 0;

char get_char = ' '; //read serial

// wait for incoming data
if (Serial.available() < 1) return; // if serial empty, return to loop().

// parse incoming command start flag
get_char = Serial.read();
if (get_char != START_CMD_CHAR) return; // if no command start flag, return to loop().

// parse incoming command type
ard_command = Serial.parseInt(); // read the command

// parse incoming pin# and value
pin_num = Serial.parseInt(); // read the pin
pin_value = Serial.parseInt(); // read the value

// 1) GET TEXT COMMAND FROM ARDUDROID
if (ard_command == CMD_TEXT){
inText =""; //clears variable for new input
while (Serial.available()) {
char c = Serial.read(); //gets one byte from serial buffer
delay(5);
if (c == END_CMD_CHAR) { // if we the complete string has been read
// add your code here
break;
}
else {
if (c != DIV_CMD_CHAR) {
inText += c;
delay(5);
}
}
}
}

// 2) GET digitalWrite DATA FROM ARDUDROID
if (ard_command == CMD_DIGITALWRITE){
if (pin_value == PIN_LOW) pin_value = LOW;
else if (pin_value == PIN_HIGH) pin_value = HIGH;
else return; // error in pin value. return.
set_digitalwrite( pin_num, pin_value); // Uncomment this function if you wish to use
return; // return from start of loop()
}

// 3) GET analogWrite DATA FROM ARDUDROID
if (ard_command == CMD_ANALOGWRITE) {
analogWrite( pin_num, pin_value );
// add your code here
return; // Done. return to loop();
}

// 4) SEND DATA TO ARDUDROID
if (ard_command == CMD_READ_ARDUDROID) {
// char send_to_android[] = "Place your text here." ;
// Serial.println(send_to_android); // Example: Sending text
Serial.print(" Analog 0 = ");
Serial.println(analogRead(A0)); // Example: Read and send Analog pin value to Arduino
return; // Done. return to loop();
}
}

// 2a) select the requested pin# for DigitalWrite action
void set_digitalwrite(int pin_num, int pin_value)
{ int delayval = 500;
switch (pin_num) {
case 13:
pinMode(13, OUTPUT);
digitalWrite(13, pin_value);
// add your code here
break;
case 6:
pinMode(6, OUTPUT);
// For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
for(int i=0;i<NUMPIXELS;i++){
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(0,150,0)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
break;
case 5:
pinMode(5, OUTPUT);
digitalWrite(5, pin_value);
// For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
for(int i=0;i<NUMPIXELS;i++){
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(0,150,0)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}

ho provato a collegare un led, con il telefono riesco ad accendere e spegnere il led..
la striscia invece si accende soltanto

Servirebbe lo schema di collegamento per capire, se funziona con il led deve esere un problema risolvibile facilmente

Testato:
Servirebbe lo schema di collegamento per capire, se funziona con il led deve esere un problema risolvibile facilmente

allora con i due tasti dal telefono come dicevo sopra riesco ad accendere e spegnere un semplice LED.
le due strisce adesso possono essere comandate separatamente, non ricordo se sopra avevo chiesto come fare ma ora riesco a farle accendere tutte e due con due tasti del telefono, con animazioni programmate e colori diversi, il problema è che una volta che le faccio accendere non riesco ne a spegnerle e ne a far ricominciare l'animazione, nemmeno toccando il tasto reset sull'arduino.. devo staccare l'alimentazione per farle spegnere..
comunque le due strisce sono collegate così tutte e due vanno a 5V e GND, le strisce hanno due GND come vedi in foto https://www.adafruit.com/images/970x728/1426-04.jpg , io ne ho collegata una sola può essere questo il problema? invece i piedini VIN sono collegati sui due digitali, il 5 e il 6..

edit: risolto il problema in parte, dunque adesso riesco a spegnere le strisce insieme dal tasto reset dell'arduino, il problema non è nella GND in quanto una vale l'altra.. in ogni caso dal telefono riesco solo ad accenderle..

@guixi:
nell'IDE è ancora presente una voce che recita "esporta codice per forum" ma non va usata, crea un simil-codice in HTML e non include invece il codice nella text area apposita, che può essere fatta scorrere. Copia semplicemente il codice con un CTRL+C e poi incollalo all'interno dei tag che compaiono premendo il pulsante con il simbolo "<>" che vedi sulla parte destra delle icone presenti sopra alle emoticons.