Lab 2: Bi-directional communication and accelerometers
- Due 4 Apr 2022 by 23:59
- Points 1
- Submitting a text entry box, a media recording, or a file upload
- Available 28 Mar 2022 at 9:00 - 25 Jul 2022 at 23:59
By the end of this lab you should be able to send and receive continuous accelerometer data to/from another lab group! It will look like magic!
You will have learnt more about bi-directional communication on class meeting 3.
NOTE 1: As evident as it may sound, if you don't fully read these instructions you will find it hard to complete this assignment.
NOTE 2: Before starting this lab make sure you have uploaded the video for the previous lab, otherwise you will lose time mounting/dismounting components on your Arduino when switching assignments.
NOTE 3: When doing this lab, you should only power the transceiver and the accelerometer from the 3.3V output in the Arduino. If you use 5V you can break them, so stay on the safe side --no matter what tutorials or strangers online sometimes say :)
NOTE 4: If your project group has a good reason to NOT gather to test the radio communication, contact the teachers asap (don't start the "Lab procedure") and they will propose an alternative.
0. Preparatory tasks (to be completed BEFORE the lab session):
1. Find another lab group and pair up with them.
2. The four of you should sign up to one "Project group", in the tab "People". Later in the course, you will collaborate again with that same group to create the final project.
3. Read this material about the accelerometer
Links to an external site. skipping the step about soldering (but contact a teaching assistant if your pin strips actually need soldering). To run the 'sensortest' example you will have to install some libraries: you can use the search function of the "Manage libraries" tool in your IDE.
If needed, you can get more info about libraries here
Links to an external site..
If you get stuck and end up consulting other tutorials about this accelerometer, take into account that they may contain mistakes. We know of a popular tutorial from Sparkfun that has several errors regarding the calibration steps (showing the importance of not just copy-pasting codes found online, but critically examining them and understanding what they do). Consult with us if in doubt!
4. Wire up your accelerometer and get it working. If you use the 'sensortest' example to create a simplified version of the code, pay particular attention to the setup() and not just to the loop(). Use the serial plotter and learn how the accelerometer actually works.
5. Apply a filter from Lab 1 to smoothen the data (this is fundamental because the readings are very sensible to noise).
Advice: You can also calibrate the accelerometer following the tutorial --a process that might seem tedious but will give you more accurate readings. You don't need to do the calibration to pass this lab, but if you end up using an accelerometer in your project (which is very probable), you will definitely have to calibrate it to get proper results, and so it might be better to start practicing now and getting formative feedback.
1. Lab procedure (you can start before the lab session):
1. Read or watch this tutorial about the RF transceivers.
Links to an external site. Focus on the bi-directional example! (Basically, don't be scared of scrolling down or ctrl+F keywords!). In case you need it, here is the video: https://www.youtube.com/watch?v=7rcVeFFHcFM
Links to an external site.
2. Wire up your transceiver and program it with the bi-directional communication code from that tutorial. You will, of course, have to adapt this code to the sensor that you have (i.e. the accelerometer rather than the servo, button, led, etc.). At this point you should arrange with the other group who will be initially the transmitter and who will initially be the receiver (the code will be almost the same given that you are using the same elements, but the reading and writing pipes will be inverted, as well as the addresses). In any case, you will be both transmitting and receiving data!
Note that these transceivers can communicate over 100 different channels, and that there can be interference. You should set yours on the same channel as your project group number (in both nodes). Add this line to the code:
radio.setChannel(33); // CHANGE the '33' TO YOUR PROJECT GROUP NUMBER
If you are going to be at a considerable distance it might be good to also set the transmission strength to the maximum level, so you should modify the line that sets the signal level, BUT you should check that you are delivering enough power (e.g. adding a capacitor, while still using the 3.3V pin!):
radio.setPALevel(RF24_PA_MAX);
(It might also happen that your radios are actually too close to each other for that high signal strength, and this can also cause problems, in which cause you should place them farther apart, OR not set the level to max. Trial and error here is key! You probably won't get it working at the first attempt and that's perfectly normal. Other times, you will get it working one day and the next inexplicably doesn't work. Allow yourselves a bit of patience.)
Prior to meeting the other group, you should be ready for testing with them.
5. Meet the other group (please respect social distance, wear masks, and if you can, meet outdoors) and get the bi-directional radio communication to work.
6. Send all 3 axes from the accelerometer wirelessly to each other, and validate that it works in both directions.
7. Document each working node through a short video showing the accelerometer data being transmitted wirelessly and received from the other group, using the Serial Plotter. It is really up to you to record together with the other group or to make your own separate video. In any case, each lab group should follow this checklist (otherwise, we won't be able to assess your submission, and so you'll have to shoot it again):
- Show the circuit. Briefly explain the wiring and the components in use (especially the accelerometer and tranceiver), and the communication protocols involved.
- Walk us briefly through the code, explaining how it works (especially the bi-directional communication). It's ok to be really brief about the filter and the calibration (if you did the latter).
-
Show the interaction in action. Make sure that we can see the screens with the serial plotter of both computers and the two accelerometers at the same time.
8. Upload the video and the code. You can decide which pair's code to upload, or to upload both (they should be very similar). Listing the lab and project numbers, and the group members in the code (as a comment) and in the name of the files, helps your teachers a lot when going through Canvas for grading.
9. You can write an optional, brief piece of feedback explaining if you struggled with anything in the description of this assignment (not its resolution) and your suggestion for improvement. You can upload this together with point 8, or as a submission comment.
2. Lab session:
During the lab session, the teachers will be available to help you if you have got stuck with the assignment.
For those connecting remotely, we will use a queuing system to make it fair and organised. So, if you have trouble completing the lab AND after looking for info online you are still stuck, OR towards the end of the session you simply want to show us what you did, then you sign up here: https://queue.csc.kth.se/ (look for DM1588).
Please indicate there your group number, your Zoom meeting link (make sure it is not password protected) and whether you require help or just want to show us your nice results (this is optional). When it is your turn, a teacher will join your Zoom meeting and will label your group in the queue as being helped.
We also have physical classrooms assigned to us along the course (you can see this on the official schedule in KTH Social). We will do our best to have at least one teacher physically there (maximum 2 teachers) to help those who really want in-person assistance. This will depend on how we assess the risks regarding the pandemic, which may change from one week to another, so please let's be patient with each other and respect social distance, etc. You can also use the classrooms during the assigned slots if you need a space to gather with your group, even if you don't need the teachers' assistance.