[Emakefun]](http://www.emakefun.com)
- Support 8-channel ADC detection
- Built-in MCU
- Support Raspberry Pi 2B/3B/3B+/4/zero
- 5.5x2.1 DC head and terminal power supply
- Freely switch between external sensor voltage 3V3 and 5V
- Onboard DC-DC step-down chip Wide voltage input: 5 ~ 36V Voltage output: 5V Maximum current output: 3A
-Onboard DC-DC step-down chip Wide voltage input: 5 ~ 36V Voltage output: 5V Maximum current output: 3A
- MCU :STM32
- IO: 8-channel ADC detection
- Communication method with Raspberry Pi: I2C
- I2C address: 0x24
The MCU I2C address of the expansion board is 0x24, and the registered address is explained as follows:
-
0x10 ~ 0x17: read ADC raw data
-
0x20 ~ 0x27: read input voltage(mv)
-
0x30 ~ 0x37: Read the ratio of input voltage to output voltage Input voltage / output voltage(0~100)
Open the Raspberry Pi terminal and enter the "sudo raspi-config" command, then follow the sequence shown below.
The above is to open the Raspberry Pi I2C. Next, we install the Raspberry I2C library and type "sudo apt-get install i2c-tools" in the terminal. After the input is complete, you can see that the I2C library is being downloaded. After the installation is complete, you can enter " sudo i2cdetect -l "detects whether the installation is correct. If a message similar to the following appears, the installation is normal.
Enter "sudo i2cdetect -y 1" command in the terminal to scan all I2C devices connected to the I2C bus and print out the I2C bus address of the device, and the I2C address of our expansion board is 0x24.
!!! Edit the config.txt file to set the Raspberry Pi IIC bus speed
sudo nano /boot/config.txt
Look for the line that contains "dtParam =i2c_arm=on" and add ", i2c_arm_baudrate=100000 "where 100000 is the new speed (100kbit /s), notice the comma before i2c. The complete code is as follows:
dtparam=i2c_arm=on,i2c_arm_baudrate=100000
This enables the I2C bus and also completes the new baud rate setup. When you're finished editing, use Ctrl-X, then Y, save the file and exit. Restart Raspberry Pi to make the new Settings take effect:
sudo reboot
As we all know, there is no ADC in Raspberry Pi, so the analog value of the sensor cannot be read directly. With the help of the MCU STM32 built into the expansion board, a 12-bit ADC can be read. This means that analog sensors can be used on the Raspberry Pi, and there are a total of 8 available interfaces.
The analog sensor inputs the analog voltage to the 12-bit analog-to-digital converter. After the analog-to-digital converter converts the analog data to digital data, the digital data is input to the Raspberry Pi via I2C.
import time
import smbus as smbus
ADC=smbus.SMBus(1)#Declare to use I2C 1
while True:
ADC.write_byte(0x24,0x10)#Write a byte to the slave
print(ADC.read_word_data(0x24,0x10))#Raspberry Pi reads the data returned by the expansion board and prints it out
time.sleep(1)#
#include<stdio.h>//Import basic library
#include<wiringPi.h>//Import Raspberry Pi WiringPi encoding IO control library
#include<wiringPiI2C.h>//Import Raspberry Pi WiringPi coded I2C control library
int value;//Define a variable
int main (void){
wiringPiSetup();//Initialize WiringPi encoding.
wiringPiI2CSetup(0x24);//Open the I2C device, 0x24 is the MCU I2C address on the expansion board
while(1){
wiringPiI2CWrite(0x24,0x10);//Write a byte to the slave
value = wiringPiI2CReadReg16(0x24,0x10);//Read two bytes from the specified address of the slave and assign it to value
printf("%d\r\n",value);//Print value
delay(100);
}
}
If the following error occurs while generating the current file:
If this problem occurs, please modify the generated command and enter the settings below:
Compile g
cc -Wall -c "%f"
Build gcc
-Wall -o "%e" -lwiringPi "%f"
Lint cppc
heck --language=c --enable=warning,style --template=gcc "%f"