...
Full disclosure: the boards + environment used here are ESP32s - we do not actually use them in NER (instead, currently all of our boards are STM32s). The tooling here is quite simple, but don't be surprised if its a bit different than what you use after completing this. Similarly, ESPs are known for their Bluetooth capabilities - and while our car doesn't use Bluetooth, I thought it would be really cool to take advantage of it here. Again, this is just supposed to be a fun intro into embedded development that is a little bit more advanced than what you may see in a class like cornerstone- nothing more. Have fun and please ask questions as they come up! We will have dedicated time in the first several meetings of the semester to talk about this, but please slack us anytime throughout the week as needed!
...
Hopefully you’ve done the full setup described throughout this doc. If you have, the launchpad subsystem is embedded into your venv already! in your terminal, simply run
Code Block |
---|
launchpad install |
You should be greeted with a message - and this sets up the ESP32 specific tooling. Youll In order for these changes to be recognized, you should deactivate and then reactivate the ner-venv
You'll need to then clone the launchpad repo - place it in the same NER folder described in the setup.
...
Your goal is to create a simple application that utilizes a few of the tools embedded into the ESP chip:
Bluetooth (duh)
Hall Effect Sensor (magnetic field strength)
...
continuously read magnetic field data and both
blink an LED based on the strength of that field (stronger field == faster blinking)
Broadcast the raw data over Bluetooth
Utilize an interrupt (ISR) to precisely time trigger the blinking of an LED blink
Broadcast the raw data over Bluetooth
The repository contains some starter/outline code for you. There, the peripherals are initialized, and the thread/task outlines are provided. When finished, you can also take a look at my completed example.
Thats That's all! You are not expected to necessarily know anything about freeRTOS, interrupts, or any of these skills; Just because I haven’t in detail explained these things in this doc does not mean you are expected to understand it. Ask questions, do some individual investigation, or use whatever tools you want to help. freeRTOS and interrupts are used extensively in our vehicle apps, so getting some experience with them here will help out.
...
Once your code is ready to build, and assuming you’ve run “launchpad” “launchpad install” in the venv, you can do so with the following command:
Code Block |
---|
pio buildlpbuild |
To upload the build code, run
Code Block |
---|
pio run --target uploadlprun |
To view the bluetooth Bluetooth data, download the NRF connect app on your phone. In the scanner, you should see an ESP device. Connect to that and you should be able to see the message!
4. Tips/keep in mind
The value returned from the sensor is a raw ADC value. This means it is a unit less unitless value, understood as a strength “percentage”. To understand this value, the resolution of the ADC needs to be known. You'll notice the starter code defines this as 12 bits. This value is simply the number of bits used to depict this percentage - the more bits, the higher the precision you are able to achieve.
Ex. for a ADC with 16 12 bit resolution:
The highest number that can be expressed with 16 bits is 2^16 = 655364096. A raw ADC value of 327682048, for instance, means 50% “strength”. Really, its just looking at this value as a percentage of the resolution.
...
The hall sensor normally would need to be calibrated to account for the ambient magnetic field in your environment. Doing so is out of scope of this task, so don’t worry about it too much, just try to set it up so that the light does not blink much at the reading level it gets without the magnet nearby. Depending on your environment, this might be at different reading values. All apps have the same ADC resolution, but you may read stronger or weaker fields, which is okay. Regardless, the strength should increase as the magnet gets closer. To test this, you may want to simply guess and check - you should incorporate some sort of “offset” ADC value, where the LED barely blinks if the reading is as low as you record when no magnet is nearby.
Again, please ask questions!