The CGMMSTICK and CGCOLORMAX are all about interfacing to hardware. MMBasic supports simple control of the data lines as well as asynchronous serial communication, SPI, I2C, PWM, analog input, and other useful interface functions.
SIMPLE INPUT AND OUTPUT
You can configure an external I/O pin using the SETPIN command, set its output using the PIN()= command and read the current input value using the PIN() function. Digital I/O uses the number zero to represent a low voltage and any non-zero number for a high voltage. An analogue input will report the measured voltage as a floating point number.
The CGMMSTICK Maximite has 20 I/O pins numbered 1 to 20. (See J1 Pinout) Pins 1 to 10 can be used for analog input and digital input/output with a maximum input voltage of 3.3V. Pins 11 to 20 are digital only but support input voltages up to 5V and can be set to open collector.
Normally digital output is 0V (low) to 3.3V (high) but you can use open collector to drive 5V circuit. This means that the pin can be pulled down (when the output is low) but will go high impedance when the output is high. With a pull up resistor to 5V an output configured as open collector you can drive 5V logic signals. Typical value of the pull up resistor is 1K to 4.7K.
CGCOLORMAX “ARDUINO SHIELD” CONNECTOR
In addition to the 20 I/O pins described above the CGCOLORMAX Maximite has an extra 20 I/O pins on the Arduino compatible connector (40 I/O pins in total). These are labeled D0 to D13 and A0 to A5.
You can use the labels D0, D1, etc in the SETPIN and PIN statements or you can use their corresponding numbers (D0 = 21, D1 = 22, etc and A0 = 35, A1 = 36, etc). The digital pins (D0 to D13) have the same characteristics (5V, open collector, etc) as the digital pins 11 to 20 and the analog capable pins (A0 to A5) have the same capabilities as pins 1 to 10.
Two serial ports are supported with speeds up to 19200 baud with configurable buffer sizes and optional hardware flow control. The serial ports are opened using the OPEN command and any command or function that uses a file number can be used to send and receive data.
Communications to slave or master devices on an I2C bus is supported with eight commands MMBasic fully supports bus master and slave mode, 10 bit addressing, address masking and general call, as well as bus arbitration (ie, bus collisions in a multi-master environment).
The Serial Peripheral Interface (SPI) communications protocol is supported with the SPI command.
The 1-Wire protocol is also supported.