Using Ethernet, we will be hosting a TCP server on the WCH CH32V307 and creating our IoT garden with monitoring through humidity, temperature and soil sensor. The data will be collected and plotted on a PC interface.
Creating HardwareThe first sensor is the DHT21 AM2301 Temperature & Humidity Sensor. It has a simple one-wire connection to the microcontroller.
The second sensor is the Capacitive Soil Moisture Sensor Module. It uses an ADC output which is linear to the soil water content.
The connections are as follows.
- VCC - 3V3
- GND - GND
- PA0 - AOUT (SOIL)
- PA5 - DATA (DHT)
An ethernet cable is used which connects to a USB-C adapter for my laptop, along with the USB-C data cable to power the microcontroller board.
Install MounRiver IDE from http://www.mounriver.com/
Download the CH32V307 example RT-Thread project from this repository and copy it into your workspace folder.
In this case, I copied the entire folder and renamed it to my-hackster-project.
Import it in the MounRiver IDE.
- Go to File > Import > Import from existing project
- Choose the my-hackster-project folder
- Click on Finish
If you realise that "ch32v30x" drivers are missing from this example project so it cannot be built. In this case, create a new baremetal project too. We will be copying over the missing drivers.
- Go to File > New MounRiver project
- Choose CH32V307
- Click on Finish
You should have 2 project like this.
- Right click on the Peripheral folder to copy it. Paste it into my-hackster-project.
- Right click on the Debug folder to copy it. Paste it into my-hackster-project.
The project should now be able to build.
- Project > Build Project
- Flash > Configuration: choose the current project hex file
- Flash > Download
If it goes well, you will see the program running when you connect serial port at baudrate of 115200.
Copy all the networking related driver files from the example template (NetLib and HTTP)
I pasted it into my project drivers
folder. And it should look like the following (highlighted in blue are the additions).
In MounRiver Studio, go to Properties >> C/C++ Build >> Settings >> Cross C Linker >> Libraries
.
Note: When your library is named libwchnet.a you must enter "wchnet" in the project properties. The linker will add the rest.
Now copy the TcpServer example main. We will be making a TCP server for our IoT sensor network
ResultsIn the picture, a the soil sensor is enclosed in a green housing which is 3D printed casing.
Upon plotting over a few minutes, the soil sensor tends upwards as it is being watered (lower left of the picture) and the diffusion of water to the sensor (top middle of picture). However, it is noted that the values are noisy and require a low-pass digital filter.
Comments