Loading...
Pages: [1]   Go Down
Author Topic: firmata + processing problema esempi  (Read 301 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Code:
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;
  }
}
Logged

0
Offline Offline
Tesla Member
***
Karma: 87
Posts: 8493
:(){:|:&};:
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

il codice non è errato, sembra più un problema di Firmdata... devi postare un issue all'autore: https://github.com/triddle/Firmdata
Logged

my Arduino code: https://github.com/lestofante/arduinoSketch
sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Code:
/*
 * 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();
    }
}
Logged

0
Offline Offline
Tesla Member
***
Karma: 87
Posts: 8493
:(){:|:&};:
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ah,scusa, il sito ufficiale è firmdata.org.

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)
Logged

my Arduino code: https://github.com/lestofante/arduinoSketch
sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

risolto grazie comunque.
era un problema in processing .
si può chiudere
Logged

ivrea (to)
Offline Offline
God Member
*****
Karma: 15
Posts: 911
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Gentilmente, puoi spiegare comunque cosa non andava e come hai risolto? Sarà utile per qualcuno che in futuro avrà lo stesso problema.  smiley-grin
Logged

Pages: [1]   Go Up
Print
 
Jump to: