344 Bachiochi – Listing 1

Listing 1
Shown here is an Arduino sketch to allow an Arduino to read and write to an I2C slave device.

const String SignOn = “I2C Dual Current”;

#include <Wire.h>

int Index = 0;
unsigned char Data[6];
int I2C1 = 0x10;
int Current1 = 0;
int Current2 = 0;
int Scale = 0;
int I2CAddress = 0;

void setup()
// I2C Start
Wire.begin(); // join i2c bus
// I2C End
Serial.begin(9600); // start serial for output
Serial.println(SignOn); // print message

void loop()
// Get the Currents

void DisplayCurrent()
// Display the Currents
Serial.print(“Amps: “); // print the character
Serial.print(Current1Scale/1000.0); // print the character Serial.print(“ “); // print the character Serial.print(Current2Scale/1000.0); // print the character
Serial.print(“ Scale: “); // print the character
Serial.println(Scale); // print the character

int SampleCurrent()
Current1=Data[0]256; Current1=Current1+Data[1]; Current2=Data[2]256;

int ReadCurrent(int Address)
Wire.beginTransmission(Address); // transmit to device
Wire.write(0x00); // sends pointer value byte
Wire.endTransmission(); // stop transmitting
Wire.requestFrom(Address, 6); // request 6 bytes from slave device
int result = 0;
while (Wire.available())
Data[result] = Wire.read(); // receive a byte as character

return result;

Keep up-to-date with our FREE Weekly Newsletter!

Don't miss out on upcoming issues of Circuit Cellar.

Note: We’ve made the Dec 2022 issue of Circuit Cellar available as a free sample issue. In it, you’ll find a rich variety of the kinds of articles and information that exemplify a typical issue of the current magazine.

Would you like to write for Circuit Cellar? We are always accepting articles/posts from the technical community. Get in touch with us and let's discuss your ideas.

Supporting Companies

Upcoming Events

Copyright © KCK Media Corp.
All Rights Reserved

Copyright © 2024 KCK Media Corp.