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 HS sensor
Part : Setting up the development toolchain
Load Mbed Studio. In the top left, go to FileNew Program... to make a new program.
Select empty MBed OS program
Call your program something meaningful, eg: your first initialyour last nameLab
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 customtargets.json we will modify the json file to create a custom build target for our Arduino:
Rename MYTARGET" to "ARDUINONANOBLESENSE".
Change the value of the "inherits" key to "ARDUINONANOBLE"
Be sure to add a comma after this line!
Add the keyvalue pairs: in the same format as "inherits" o Key: "OUTPUTEXT", Value: "bin"
Be sure to add a comma after this line!
o Key: "mbedappstart", Value: x Press CtrlS to save the target
Select the new target in the Target dropdown. o In the Target dropdown, select your newly created target.
Create a git repository in your programs directory if there isnt one already.
Move the Arduino Command Line ArduinoCLI tool and arduinoupload.bat to the root folder.
Part : 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 readhumidity and readtemperature, 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 nonreentrant, which could cause issues with concurrent access; use Mutexes to protect these resources.
Part : IC
IC 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 HS temperature and humidity sensor You will find documentation on DL for the sensor; this documentation contains addresses, rules for communication, as well as calibration instructions for your sensor Use MBeds IC class for communication.
Obtain and establish the necessary calibration functions for pressure and temperature. Once you have calculated the calibration constants, modify the readhumidity and readtemperature 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 readhumidity and readtemperature threads.
Test it out by breathing on your chip! Take screenshots of at least 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 IC at idle requires SCL and SDA to be high. Thus, you will want to pull uphold high the IC bus itself. You can do this by manipulating Port Pin
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
