Skip to content

GridlessCompute/Jua-Kali-Arduino

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bluecollar Arduino Controller

This Arduino sketch serves as a versatile controller, performing two primary functions:

  1. I2C Peripheral Emulation: It emulates a power supply unit, responding to I2C commands as a slave device.
  2. Current Sensing: It reads analog data from current sensors, converts it to Amperage, and outputs the values to the serial monitor.

Features

  • I2C Slave Emulation: Emulates an I2C device at address 0x58.
  • Command Processing: Responds to a variety of I2C commands to simulate a power supply's status and readings.
  • Analog Current Measurement: Reads from three analog pins (A0, A1, A2) to monitor current.
  • Serial Output: Prints the measured current values to the serial port for debugging and monitoring.

Hardware Requirements

  • An Arduino-compatible board (e.g., Arduino Uno, Nano).
  • I2C bus connection for communication with a master device.
  • Up to three analog current sensors connected to pins A0, A1, and A2.

Software Breakdown

main.cpp

This is the main file for the sketch.

  • setup():

    • Initializes serial communication at 9600 baud.
    • Initializes the I2C bus with slave address 0x58.
    • Registers the requestEvent and receiveEvent handlers for I2C communication.
  • loop():

    • Continuously reads analog values from pins A0, A1, A2.
    • Converts the raw analog-to-digital converter (ADC) readings into Amperage.
    • Prints the current values for each sensor to the serial monitor.
    • Includes a 500ms delay to control the reading frequency.
  • convert_voltage_in(int reading):

    • Takes a raw ADC reading as input.
    • Converts the reading to a voltage value based on the system's VOLTAGE (3.3V).
    • Calculates the current in Amps based on the sensor's characteristics.
  • receiveEvent(int byteCount):

    • This function is called whenever the I2C master sends data to this slave device.
    • It reads the incoming byte, which is treated as a command code for the requestEvent handler.
  • requestEvent():

    • This function is called whenever the I2C master requests data from this slave device.
    • It uses a switch statement to check the last command code received via receiveEvent.
    • Based on the command, it sends back predefined data, emulating the behavior of a power supply. This includes responses for operation status, voltage/current readings, manufacturer information, and more.

Usage

  1. Hardware Setup:

    • Connect your Arduino board to your computer.
    • Connect the I2C master to the SDA and SCL pins of your Arduino.
    • Connect your analog current sensors to pins A0, A1, and A2.
  2. Flashing the Sketch:

    • Open the main.cpp file in the Arduino IDE or your preferred editor.
    • Select the correct board and port.
    • Upload the sketch to your Arduino.
  3. Monitoring:

    • Open the Serial Monitor in the Arduino IDE.
    • Set the baud rate to 9600.
    • You will see the current readings from the connected sensors printed to the monitor.
  4. I2C Communication:

    • Your I2C master device can now communicate with the Arduino at address 0x58.
    • To read data, the master should first write a single command byte (e.g., 0x8B to read VOUT) and then immediately request data from the slave.

About

Arduino File for faking an M30s Power Supply And Reading Current Sensors

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages