Question: Can you write the code needed for this project? Objectives: Read temperature and humidity from the HS 3 0 0 0 sensor . Part 1

Can you write the code needed for this project?
Objectives: Read temperature and humidity from the HS3000 sensor.
Part 1: Setting up the development toolchain
1. Load Mbed Studio. In the top left, go to File->New Program... to make a new program.
Select empty MBed OS program
Call your program something meaningful, e.g.: [your first initial][your last name]_Lab2
o Update the version of mbed by going to the libraries tab on the bottom, and clicking the circular arrow button.
o As before, make a custom target using Mbed Studio:
From the Target dropdown, click the chip icon on the right.
On the window that pops up, click the file icon next to the Build Target dropdown.
In the tab that opened (named custom_targets.json), we will modify the json file to create a custom build target for our Arduino:
Rename "MY_TARGET" to "ARDUINO_NANO33BLE_SENSE".
Change the value of the "inherits" key to "ARDUINO_NANO33BLE"
**Be sure to add a comma after this line!
Add the key/value pairs: (in the same format as "inherits") o Key: "OUTPUT_EXT", Value: "bin"
**Be sure to add a comma after this line!
o Key: "mbed_app_start", Value: "0x10000" Press Ctrl-S to save the target
Select the new target in the Target dropdown. o In the Target dropdown, select your newly created target.
2. Create a git repository in your programs directory if there isnt one already.
3. Move the Arduino Command Line (Arduino-CLI) tool and arduino-upload.bat to the root folder.
Part 2: ISRs
As discussed in class, interrupts and ISRs by nature take immediate and complete control of the CPU, meaning that all actions within them should be very brief. For this part you will be designing an ISR that uses Tickers and EventFlags to regularly interrupt, and react to, an interrupt.
Write an ISR linked to a Ticker that sets event flags for two conditions, named HUMIDITY and TEMPERATURE. The ISR should alternate between setting either flag.
Write a pair of threads named read_humidity and read_temperature, whose sole job in this part is to wait for their event flag. After the thread detects its event flag, it should turn on an LED, wait a reasonable amount of time, and turn the LED back off. Each thread should blink a different LED. Every time an LED turns on, print to the console that you are reading pressure or reading temperature, respectively. Save an example screenshot of the terminal and include it in the final files.
USBSerial and printf are non-reentrant, which could cause issues with concurrent access; use Mutexes to protect these resources.
Part 3: I2C
I2C is an excellent protocol for communicating with peripheral sensors, like the ones connected on our board. In this part, write routines that communicate with our onboard HS3000 temperature and humidity sensor. You will find documentation on D2L for the sensor; this documentation contains addresses, rules for communication, as well as calibration instructions for your sensor. Use MBeds I2C class for communication.
Obtain and establish the necessary calibration functions for pressure and temperature. Once you have calculated the calibration constants, modify the read_humidity and read_temperature threads to obtain pressure and temperature measurements from the sensor. Also, modify your threads to print the current pressure and temperature values to the console. Start the read_humidity and read_temperature threads.
Test it out by breathing on your chip! Take screenshots of at least 3 different environments (freezer, inside, outside) to show that your code works.
Hints:
Ensure you are talking to the correct sensor (using the Who Am I register).
What do electronic devices need to run? Your sensor is no different.
Recall that I2C at idle requires SCL and SDA to be high. Thus, you will want to pull up(hold high) the I2C bus itself. You can do this by manipulating Port 1, Pin 0.
Start trying to get one type of measurement, then work on the other.
Youll have two threads accessing a shared resource.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!