368_I2C ANALOG READ
Quote from Defran on November 14, 2024, 11:20 pm368_I2C ANALOG READ. (Simulide 1.1.2011 or Higher).
This example is based on a subcircuit (I2C_ADC) that delivers the current value of the potentiometer via I2C. This value is of one byte (between 0 and 255 in decimal). At all times this value is displayed in the SERIAL MONITOR, which must always be enabled for this purpose.
SCHEME:
The schematic is based on the Arduino UNO. The schematic is essentially the I2C-ADC subcircuit (address 0x50, 80dec.) connected to the I2C bus. The structure of this subcircuit is composed of two primitive Simulide functions: the I2CtoParallel and the ADC converter. The ADC input is connected to the potentiometer. The I2CtoParallel converts its input byte into a protocolized output structure on the I2C bus where it is sent to the controller. This I2C_ADC subcircuit is inside "data" of the attached Zip.
PROGRAM:The external library used is: pcf8574.h Ver 1.0.3. We use this library because it handles the primitive I2CtoParallel function, whose commercial IC is the PCF8574. The program simply collects the data from the I2CParallel and displays it in decimal format on the CONTROLLER SERIAL MONITOR. The data will vary between the values cited if the potentiometer is manually moved.
// ADC READ BY I2C. DEFRAN 24 #include <pcf8574.h> PCF8574 AnaSense(0x50); // Address 0x50, 80dec. void setup() { delay(200); Serial.begin(9600); pinMode(AnaSense,0,INPUT_PULLUP); } void loop() { int DATA=AnaSense.read(); Serial.println(DATA); // Serial.println(DATA, BIN); delay(500); }
SUBCIRCUITS:This example integrates several subcircuits located in the "data" folder into the ZIP attached. This folder must always be next to the "sim1" scheme so that it can be executed. A subcircuit is a “custom” circuit that accumulates a set of Simulide base components (primitive function) to obtain a new or an adapted function. These subcircuits are treated by Simulide as another component of its own structure. User can create his own subcircuits or use the ones published here in your own designs once the procedure is known, explained in detail in the Simulide tutorials: https://simulide.com/p/subcircuits/More examples for Simulide are here: https://simulide.forumotion.com/f12-projects-made-in-simulide* Communication with the author: Simulide/User/Messages/DefranP. de Francisco.
368_I2C ANALOG READ. (Simulide 1.1.2011 or Higher).
This example is based on a subcircuit (I2C_ADC) that delivers the current value of the potentiometer via I2C. This value is of one byte (between 0 and 255 in decimal). At all times this value is displayed in the SERIAL MONITOR, which must always be enabled for this purpose.
SCHEME:
The external library used is: pcf8574.h Ver 1.0.3. We use this library because it handles the primitive I2CtoParallel function, whose commercial IC is the PCF8574. The program simply collects the data from the I2CParallel and displays it in decimal format on the CONTROLLER SERIAL MONITOR. The data will vary between the values cited if the potentiometer is manually moved.
// ADC READ BY I2C. DEFRAN 24
#include <pcf8574.h>
PCF8574 AnaSense(0x50); // Address 0x50, 80dec.
void setup()
{
delay(200);
Serial.begin(9600);
pinMode(AnaSense,0,INPUT_PULLUP);
}
void loop()
{
int DATA=AnaSense.read();
Serial.println(DATA); // Serial.println(DATA, BIN);
delay(500);
}