HMC E155 Lab 6: The Internet of Things and Serial Peripheral Interface
Introduction
In this lab, a DS1722 digital temperature sensor was configured over SPI communications to report temperature when prompted. Simultaneously, an ESP8266 chip was used to host a local server with a website programmed using HTML that was communicated over UART. This website controlled an LED on the demo board, reported temperature and LED status, and allowed changing of LED precision between 8 and 12 bits.
Schematic
The below schematic shows how this circuit was constructed. The DS1722 was connected to a 3V3 power line on three of its pins, the four SPI connections were made with the MCU, and the chip was grounded to the MCU ground.
Figure 1: Electrical schematic for system
Results and Discussion
Temperature Sensing
After initializing, every request from the webpage successfully sent an SPI communication to the DS1722 that updated temperature resolution if necessary, then reported the current temperature of the sensor in Centigrade. This temperature successfully showed changes in precision, showing only an “integer” for 8-bit (no fractional measurement), down to 4 digits of precision for 12-bit (4 bits of fractional measurement). The below digital oscilloscope trace shows a sample SPI transaction, which is reading from register 0x01, the read-only address for the MSBs of the measurement. This was done in 8-bit mode, so showing a data out packet of 0x00 shows that we have an appropriate communication taking place.
Figure 2: Digital oscilloscope trace
Conclusion
In this lab, SPI communications were used to interface with a DS1722 temperature sensor and report these temperatures to a webpage on an external chip over UART communications. This lab took me 8 hours overall.
AI Prototype
Following the directions for the AI Prototype for lab 6, the following prompt was passed into ChatGPT:
I’m making a web portal to interface with a temperature sensor. Create a HTML page that looks good and is intuitive to show the temperature, control an LED, and change the precision of the readout.
The AI Model created a website that can be seen below, and it is quite good! It’s even rather aesthetic. Based on prior use I’ve seen for AI, it is very good at JavaScript, TypeScript, HTML, and CSS, so I’m not surprised by its success in this task. It could definitely be tweaked to do exactly what we want in this lab
Figure 5: Website generated by ChatGPT
ChatGPT was then fed another prompt as stated below:
Write me a C function to carry out a SPI transaction to retrieve a temperature reading from a DS1722 sensor. Make use of CMSIS libraries for the STM32L432KC.
In response to this prompt, the AI actually wrote code very similar to mine! It instead used an active low chip select, and it also used some of the CMSIS functions and shorthands incorrectly. However, I think the general idea is here and it could be doctored to do what we desire. The SPI code can be seen below.
Figure 6: Code for SPI initialization from ChatGPT