Example Code for Raspberry Pi-Store the DAC Value in EEPROM
The guide of storing DAC values in the EEPROM of a Raspberry Pi using the DFRobot Gravity 12-Bit I2C DAC Module. It details the necessary hardware and software preparations, connection setup, and provides sample code for implementation. The result is a consistent analog voltage output that is retained even upon repowering, showcasing the module's ability to recall stored values and output them effectively.
Hardware Preparation
- Raspberry Pi 4 Model B (or similar) * 1
- Gravity: 12-Bit I2C DAC Module * 1
- Gravity 4-pin sensor wire (comes with Gravity 12Bit DAC Module) * 1
- Digital multimeter (optional) x 1
- Oscilloscope (optional) x 1
Software Preparation
- Download and install the Gravity 12-Bit I2C DAC RaspberryPi library
- RASPBIAN
Wiring Diagram
Other Preparation Work
-
Connect the module to the Raspberry Pi according to the connection diagram above and set I2C address to 0x60 by ADDR switch on the module. If I2C address 0x61 is preferred, you need to modify the parameter of the function mcp4725.setAddr_MCP4725() to MCP4725A0_IIC_Address1.
-
The user can modify the OUTPUT_VOLTAGE in the OutputVoltageEEPROM.py to change the output value of the analog voltage. REF_VOLTAGE can be changed according to the calibration section. If no calibration is done, enter 5000 (5V) or 3300 (3.3V) depending on the VCC power supply.
-
In the Terminal, type in the following commands and press Enter to run the sample code:
cd DFRobot_MCP4725/RaspberryPi/Python/OutputVoltageEEPROM
sudo python OutputVoltageEEPROM.py
Result
- A 1V voltage signal can be measured at VOUT. Disconnect the module from the Raspberry Pi. Repower the module, by connecting only the VCC and GND pins of the module to 5V and GND on the Raspberry Pi, respectively. A 1V can still be read at VOUT. The function mcp4725.outputVoltageEEPROM() stores the DAC value in the EEPROM while it outputs a specified analog voltage signal. The module recalls the DAC value in the EEPROM upon power-up and restores the analog output at VOUT.
Was this article helpful?
