We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Dear community, I need to address all pins (digital and analog) of my Arduino NANO via Firmata. My Arduino Sketch is one for multiple circuits (educational purpose) and I changed all the Axxx-pins in the .pde-Sketch (see below) according to the pin map A0=14, A1=15 etc. but I got an error message for pin 18 (out of range) and I don't know how to address A6 and A7 because there are no digital numbers in the pin map for them. I tried to just use the numbers without A (A2=2 ...) but this doesn't work for me because there are conflicts with the digital pins and the use of same pin numbers. Can anyone help me how to address ALL pins by numbers? And: do I have to change the StandardFirmata to use it for the NANO and to use all the pins? Thanks in advance. KLI
import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
//Arduino.INPUTs:
int AND_1a = 14;
int AND_1b = 15;
int XOR_a = 16;
int XOR_b = 17;
int AND_2a = 18;
int AND_2b = 19;
int NOT_In = 6;
int Poti = 7;
int OR_a = 2;
int OR_b = 7;
//Arduino.OUTPUTs:
int AND_1 = 4;
int XOR = 5;
int Tank_Anzeige = 6;
int Schwell_030 = 3;
int Schwell_50100 = 8;
int Schwell_70100 = 9;
int Schwell_020 = 10;
int AND_2 = 11;
int NOT = 12;
int OR = 13;
//Variablen:
int PotiWert = 0;
int Summer_Intervall = 500; //Summer an Pin 7
int Status = Arduino.LOW;
double Warten;
void setup() {
//Arduino.INPUTs:
arduino = new Arduino(this, Arduino.list()[0], 57600);
arduino.pinMode (AND_1a, Arduino.INPUT);
arduino.pinMode (AND_1b, Arduino.INPUT);
arduino.pinMode (XOR_a, Arduino.INPUT);
arduino.pinMode (XOR_b, Arduino.INPUT);
arduino.pinMode (AND_2a, Arduino.INPUT);
arduino.pinMode (AND_2b, Arduino.INPUT);
arduino.pinMode (NOT_In, Arduino.INPUT);
arduino.pinMode (Poti, Arduino.INPUT);
arduino.pinMode (OR_a, Arduino.INPUT);
arduino.pinMode (OR_b, Arduino.INPUT);
//Arduino.OUTPUTs:
arduino.pinMode (AND_1, Arduino.OUTPUT);
arduino.pinMode (XOR, Arduino.OUTPUT);
arduino.pinMode (Tank_Anzeige, Arduino.OUTPUT);
arduino.pinMode (Schwell_030, Arduino.OUTPUT);
arduino.pinMode (Schwell_50100, Arduino.OUTPUT);
arduino.pinMode (Schwell_70100, Arduino.OUTPUT);
arduino.pinMode (Schwell_020, Arduino.OUTPUT);
arduino.pinMode (AND_2, Arduino.OUTPUT);
arduino.pinMode (NOT, Arduino.OUTPUT);
arduino.pinMode (OR, Arduino.OUTPUT);
Warten = millis();
}
void draw() {
//alle Logikgatter:
//NOT:
if (arduino.analogRead (NOT_In) > 1000) {
arduino.digitalWrite (NOT, Arduino.LOW);
}
else {
arduino.digitalWrite (NOT, Arduino.HIGH);
}
//OR:
if (arduino.digitalRead (OR_a) == 1 || arduino.digitalRead (OR_b) == 1) {
arduino.digitalWrite (OR, Arduino.HIGH);
}
else {
arduino.digitalWrite (OR, Arduino.LOW);
}
//AND_1:
if (arduino.analogRead (AND_1a) > 1000 && arduino.analogRead (AND_1b) > 1000) {
arduino.digitalWrite (AND_1, Arduino.HIGH);
}
else {
arduino.digitalWrite (AND_1, Arduino.LOW);
}
//AND_2:
if (arduino.analogRead (AND_2a) > 1000 && arduino.analogRead (AND_2b) > 1000) {
arduino.digitalWrite (AND_2, Arduino.HIGH);
}
else {
arduino.digitalWrite (AND_2, Arduino.LOW);
}
//XOR:
if ((arduino.analogRead(XOR_a) > 1000 && arduino.analogRead(XOR_b) < 1000) || (arduino.analogRead(XOR_a) < 1000 && arduino.analogRead(XOR_b) > 1000) ) {
arduino.digitalWrite (XOR, Arduino.HIGH);
}
else {
arduino.digitalWrite (XOR, Arduino.LOW);
}
//Poti-Auswertung:
PotiWert = arduino.analogRead(Poti);
//Schwellenwert-Schalter 0...30%
if (PotiWert < 200) {
arduino.digitalWrite (Schwell_030, Arduino.HIGH);
}
else {
arduino.digitalWrite (Schwell_030, Arduino.LOW);
}
//Schwellenwert-Schalter 50...100%
if (PotiWert > 511) {
arduino.digitalWrite (Schwell_50100, Arduino.HIGH);
}
else {
arduino.digitalWrite (Schwell_50100, Arduino.LOW);
}
//Schwellenwert-Schalter 70...100%
if (PotiWert > 700) {
arduino.digitalWrite (Schwell_70100, Arduino.HIGH);
}
else {
arduino.digitalWrite (Schwell_70100, Arduino.LOW);
}
//Tankanzeige: dunkler werdende LED - PotiWert = hoch -> LED = hell
arduino.analogWrite (Tank_Anzeige, (PotiWert / 4));
if (PotiWert < 100) {
arduino.digitalWrite (Tank_Anzeige, Arduino.LOW);
}
//Tankanzeige: frequentierter Ausgang
if (PotiWert < 100) {
if ((millis() - Warten) > Summer_Intervall) {
Warten = millis();
if(Status==Arduino.LOW){
Status=Arduino.HIGH;}
else {
Status=Arduino.LOW;}
arduino.digitalWrite (Schwell_020, Status);
}
}
else {
arduino.digitalWrite (Schwell_020, Arduino.LOW);
}
}_
Answers
why you did not address all the pins in Arduino and just send the information that you required from processing vial Serial?
I need many sensor values for visualization in Processing and it would take many efforts to read the values via Serial. As far as I can seen I would have to analyze substrings and it would be much more comfortable to handle this via Firmata as own objects in Processing. The corresponding .ino-code works fine with the pure numbers as pin names for the analog pins but as soon as I tried the slightly modified sketch in processing with firmata the error message appears that certain pins are out of bound.