salve a tutti.
premetto di aver usato la fuzione cerca, sia nel forum che nel web, con scarsi risultati
uso l'esempio standard firmata e arduino output in processing, in quest ultimo dovrebbe abilitarmi 13 pin, premendo su dei pulsandi in processing i pin dovrebbero cambiare stato high o low . questo funziona fino al settimo pin, dal ottavo premendo sul pulsante corrispondente il pin di arduino non cambia stato mentre in processing si.
perchè succede questo?
grazie in anticipo a tutti
codice processing
import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
color off = color(4, 79, 111);
color on = color(84, 145, 158);
int[] values = { Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW,
Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW,
Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW, Arduino.LOW };
void setup() {
size(470, 200);
println(Arduino.list());
arduino = new Arduino(this, Arduino.list()[1], 57600);
for (int i = 0; i <= 13; i++)
arduino.pinMode(i, Arduino.OUTPUT);
}
void draw() {
background(off);
stroke(on);
for (int i = 0; i <= 13; i++) {
if (values[i] == Arduino.HIGH)
fill(on);
else
fill(off);
rect(420 - i * 30, 30, 20, 20);
}
}
void mousePressed()
{
int pin = (450 - mouseX) / 30;
if (values[pin] == Arduino.LOW) {
arduino.digitalWrite(pin, Arduino.HIGH);
values[pin] = Arduino.HIGH;
} else {
arduino.digitalWrite(pin, Arduino.LOW);
values[pin] = Arduino.LOW;
}
}
intanto grazie per la risposta.
il link credo sia per arduino due mentre io ho l'uno.
non posso postare il codice di standard firmata, in quanto supera i 9500 caratteri comunque è lo standard firmata di arduino.
posso mettere simpledigitalfirmata che mi da il medesimo problema.
/*
* Firmata is a generic protocol for communicating with microcontrollers
* from software on a host computer. It is intended to work with
* any host computer software package.
*
* To download a host software package, please clink on the following link
* to open the download page in your default browser.
*
* http://firmata.org/wiki/Download
*/
/* Supports as many digital inputs and outputs as possible.
*
* This example code is in the public domain.
*/
#include <Firmata.h>
byte previousPIN[TOTAL_PORTS]; // PIN means PORT for input
byte previousPORT[TOTAL_PORTS];
void outputPort(byte portNumber, byte portValue)
{
// only send the data when it changes, otherwise you get too many messages!
if (previousPIN[portNumber] != portValue) {
Firmata.sendDigitalPort(portNumber, portValue);
previousPIN[portNumber] = portValue;
}
}
void setPinModeCallback(byte pin, int mode) {
if (IS_PIN_DIGITAL(pin)) {
pinMode(PIN_TO_DIGITAL(pin), mode);
}
}
void digitalWriteCallback(byte port, int value)
{
byte i;
byte currentPinValue, previousPinValue;
if (port < TOTAL_PORTS && value != previousPORT[port]) {
for(i=0; i<8; i++) {
currentPinValue = (byte) value & (1 << i);
previousPinValue = previousPORT[port] & (1 << i);
if(currentPinValue != previousPinValue) {
digitalWrite(i + (port*8), currentPinValue);
}
}
previousPORT[port] = value;
}
}
void setup()
{
Firmata.setFirmwareVersion(0, 1);
Firmata.attach(DIGITAL_MESSAGE, digitalWriteCallback);
Firmata.attach(SET_PIN_MODE, setPinModeCallback);
Firmata.begin(57600);
}
void loop()
{
byte i;
for (i=0; i<TOTAL_PORTS; i++) {
outputPort(i, readPort(i, 0xff));
}
while(Firmata.available()) {
Firmata.processInput();
}
}
che dire, se anche i loro esempi non vanno, è un bug del loro firmware, e devi sentire loro (firmdata non è sviluppatto dalla arduino ma è indipendente)
Salve stò usando anche io un breve programma di processing su pc e firmata su arduino UNO per comandare degli output digitali ...come hai risolto ? Dici il problema è lato processing?? Io ho provato a modificare firmata senza nessun risultato. Grazie
quando usavo Firmata, ricordo che se aggiornavo processing ad una versione successiva Firmata non funzionava più.
(ho abbandonato definitivamente Firmata ascoltando qualcuno qui nel forum)
prova solo con "simple digital firmata" e prova con uscite/ingressi digitali, oppure
prova solo con "simple analog firmata" e prova solo con ingressi analogici
stò usando processing 1.5.1 con cui controllo su una semplice GUI 2 servi e un led (digital output). Se uso StandardFirmata controllo bene il led ON - OFF mentre i servi non li controllo. Se uso ServoFirmata controllo ottimamente i servi mentre il led nulla. sotto il codice di processing
// Need G4P library download at
// http://www.processing.org/reference/libraries/
// Graphic Interface - G4P
// control servo on Arduino through GUI control
import processing.serial.*;
import cc.arduino.*;
import guicomponents.*;
GWSlider sdr4;
PImage rear;
Arduino arduino; // Declare object (a variable of type arduino object)
int timestartback = 1500; // store time microsec value 90°
int timesugiu = 1500;
int step = 100;
//declare pin where servo are attached
int servoPin3 = 3; //start-back livello acqua
int servoPin5 = 5; //up-down vertical water drop
// boolean variable coincident with the buttons
boolean start = true;
boolean back = true;
boolean su = true;
boolean giu = true;
boolean HVON = true;
boolean HVOFF = true;
PFont f;
void setup() {
size(400, 287);
rear = loadImage("Satellite.gif");
f = loadFont("Arial-BoldMT-48.vlw");
println(Arduino.list());
//create a new arduino object and pass parameters( "this" refers to this sketch, name of serial port, speed)
arduino = new Arduino(this, Arduino.list()[0], 57600);
// attaches the servo on pin 3 to the servo object You need to set the mode of the pin that the servo is attached to, to SERVO
arduino.pinMode(servoPin3, Arduino.SERVO);
// attaches the servo on pin 5 to the servo object
arduino.pinMode(servoPin5, Arduino.SERVO);
arduino.pinMode(10, Arduino.OUTPUT);
createGUI();
customGUI();
// Place your setup code here
background(rear);
}
void draw() {
//700 and 2300
//controllo servo n.1
if ( start ) {//start = true;
}
else {//start = false
//println (" start è cambiato " + timestartstop );
timestartback +=step;
arduino.analogWrite(servoPin3, timestartback);
delay(200);
background(rear);
textFont(f, 16);
fill(50);
text(timestartback, 50, 70);
start = true;
}
if (back) { //back = true;
}
else {//back = false;
timestartback -=step;
arduino.analogWrite(servoPin3, timestartback);
delay(200);
background(rear);
textFont(f, 16);
fill(50);
text(timestartback, 50, 70);
back = true;
}
//controllo Servo n.2
if ( su ) {//su = true;
}
else {//su = false
timesugiu +=step;
arduino.analogWrite(servoPin5, timesugiu);
delay(200);
background(rear);
textFont(f, 16);
fill(50);
text(timesugiu, 200, 70);
su = true;
}
if (giu) { //giu = true;
}
else {//giu = false;
timesugiu -=step;
// down in steps of 1 microsec
arduino.analogWrite(servoPin5, timesugiu);
delay(200);
background(rear);
textFont(f, 16);
fill(50);
text(timesugiu, 200, 70);
giu = true;
}
// controllo LED
if (HVON) { //HVON = true;
}
else {//HVON = false;
arduino.digitalWrite(10, Arduino.HIGH);
delay(200);
background(rear);
textFont(f, 16);
fill(50);
text("ON", 200, 200);
HVON = true;
}
if (HVOFF) { //HVOFF = true;
}
else {//HVOFF = false;
arduino.digitalWrite(10, Arduino.LOW);
delay(200);
background(rear);
textFont(f, 16);
fill(50);
text("OFF", 200, 200);
HVOFF = true;
}
}
// Use this method to add additional statements
// to customise the GUI controls
void customGUI() {
}
void handleSliderEvents(GSlider slider) {
println("integer value:" + slider.getValue());
step = slider.getValue();
}
se non trovi altra soluzione, e se per caso il led funziona con anche con " simpledigitalfirmata"
quest'ultimo puoi provare ad inserirlo in "servofirmata",
ovviamente non brutalmente... i 2 sketch non son enormi. (io lo ho fatto con altro)
purtroppo non posso provare il tuo codice manca createGui
ho provato stamattina a unire SimpleDigitalFirmata e ServoFirmata,(da 1 a 6 i servi e da 8 a 12 i digital output) ma da:
Boards.h:270: error: too few arguments to function 'unsigned char readPort(byte, byte)'
#include <Servo.h>
#include <Firmata.h>
Servo servos[MAX_SERVOS];
byte previousPIN[TOTAL_PORTS]; // PIN means PORT for input
byte previousPORT[TOTAL_PORTS];
void analogWriteCallback(byte pin, int value)
{
if (IS_PIN_SERVO(pin)) {
servos[PIN_TO_SERVO(pin)].write(value);
}
}
void outputPort(byte portNumber, byte portValue)
{
// only send the data when it changes, otherwise you get too many messages!
if (previousPIN[portNumber] != portValue) {
Firmata.sendDigitalPort(portNumber, portValue);
previousPIN[portNumber] = portValue;
}
}
void setPinModeCallback(byte pin, int mode) {
if (IS_PIN_DIGITAL(pin)) {
pinMode(PIN_TO_DIGITAL(pin), mode);
}
}
void digitalWriteCallback(byte port, int value)
{
byte i;
byte currentPinValue, previousPinValue;
if (port < TOTAL_PORTS && value != previousPORT[port]) {
for(i=8; i<12; i++) {
currentPinValue = (byte) value & (1 << i);
previousPinValue = previousPORT[port] & (1 << i);
if(currentPinValue != previousPinValue) {
digitalWrite(i + (port*8), currentPinValue);
}
}
previousPORT[port] = value;
}
}
void setup()
{
byte pin;
Firmata.setFirmwareVersion(0, 2);
Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
for (pin=0; pin < 7; pin++) {
if (IS_PIN_SERVO(pin)) {
servos[PIN_TO_SERVO(pin)].attach(PIN_TO_DIGITAL(pin));
}
}
Firmata.setFirmwareVersion(0, 1);
Firmata.attach(DIGITAL_MESSAGE, digitalWriteCallback);
Firmata.attach(SET_PIN_MODE, setPinModeCallback);
Firmata.begin(57600);
}
void loop()
{
byte i;
for (i=0; i<TOTAL_PORTS; i++) {
outputPort(i, readPort(i)); //DA ERRORE QUI
}
while(Firmata.available()) {
Firmata.processInput();
}
}
Quello che non mi torna è che StandardFirmata ha sia digital che servo già inclusi e dovrebbe funzionare