hello there,
I normally use the Arduino board with Standard Firmata and control it from PD using [comport]. It is quite straight forward driving analog/digital inputs and outputs. I'd like to add a sensor that communicates using I2C but I can not find the way to read that when Firmata is installed. any tips?
arduinomega-test.pd
-
Arduino StandardFirmata reading I2C
-
I2C is a special protocol that enables communication between devices (e.g. your Arduino with another chip). I'm not use Firmata supports I2C, but I'm pretty sure you'll be better off writing your own code (probably based on examples from the sensor you want to use). Which sensor is this?
-
the sensor is Adafruit CCS811. I can read it together with analog sensors if i send the data to the serial port (not with Firmata) but then it is problematic when i want to control digital outputs from PD
-
Controlling digital I/O from Pd is not so difficult. What is it exactly that you are trying to do? You want to activate-deactivate digital pins?
-
Yes, i'd like read analog values from gas sensors, together with the I2C from the CCS811 sensor (IN) and activate/deactivate fans and servos (OUT)
i could do it with the Firmata on the board, then i don't know how to read the I2C or communicate the board with PD via [comport] and then I dont know how to send the digital OUT messages that activate the board from the serial -
Takes a bit of reading. You might want to check this tutorial https://drymonitis.me/wp-content/uploads/2023/09/Arduino_for_Pders.pdf
and these abstractions https://github.com/alexdrymonitis/Arduino_Pd -
Thanks a lot! that's super useful information, i'll do my research
However, when uploading the serial_write sketch to the board I get the following error apparently in the byte transferArray[0] = 0xc0; line 37:/run/arduino/sketches/serial_write_ADrymonitis/serial_write_ADrymonitis.ino: In function 'void loop()':
/run/arduino/sketches/serial_write_ADrymonitis/serial_write_ADrymonitis.ino:37:27: error: array must be initialized with a brace-enclosed initializer
byte transferArray[0] = 0xc0; // denote beginning of data
^~~~
/run/arduino/sketches/serial_write_ADrymonitis/serial_write_ADrymonitis.ino:44:45: error: array must be initialized with a brace-enclosed initializer
byte transferArray[index++] = analogVal & 0x007f;
^~
/run/arduino/sketches/serial_write_ADrymonitis/serial_write_ADrymonitis.ino:45:31: error: conflicting declaration 'byte transferArray [(<anonymous> + 1)]'
byte transferArray[index++] = analogVal >> 7;
^
/run/arduino/sketches/serial_write_ADrymonitis/serial_write_ADrymonitis.ino:44:10: note: previous declaration as 'byte transferArray [(<anonymous> + 1)]'
byte transferArray[index++] = analogVal & 0x007f;
^~~~~~~~~
/run/arduino/sketches/serial_write_ADrymonitis/serial_write_ADrymonitis.ino:50:35: error: array must be initialized with a brace-enclosed initializer
byte transferArray[index++] = !digitalRead(i + 2);
^~~~~~~~~~~~~~~~~~~
/run/arduino/sketches/serial_write_ADrymonitis/serial_write_ADrymonitis.ino:53:21: error: expected primary-expression before 'transferArray'
Serial.write(byte transferArray, numBytes);
^~~~~~~~~~~~~ -
That's strange. Remove the word "byte" from lines 37, 44, 45, 50, and 53. That should do it.
-
the code uploaded now, thank you!