EM Lab02 Sensor Interfacing With Raspberry Pi and Arduino
EM Lab02 Sensor Interfacing With Raspberry Pi and Arduino
Tobias Schaffer
• The Raspberry Pi Sense HAT for LED matrix display and sensor readings.
• The Arduino Nano 33 BLE Sense Rev2 for sensor data acquisition and processing.
2 Prerequisites
Students should have the following prior to starting the lab:
3 Task Description
3.1 Part 1: Raspberry Pi Sense HAT - LED Display and Sensor Readings
Headless Setup of the Raspberry Pi
Before working with the Raspberry Pi, it is useful to configure it in headless mode—meaning it can
be set up and used without an external monitor, keyboard, or mouse.
To do this, use the Raspberry Pi Imager tool to create a bootable SD card. During the setup
process:
• In the settings choose an admin username (we use ”pi”) and a password (we use ”1234”).
1/4
TH Deggendorf - Campus Cham Prof. Tobias Schaffer
To set a static IP address create a file named ’dhcpcd.conf’ with the following content in the boot
partition:
interface eth0
static ip_address =192.168.0.10/24
Once the SD card is written and inserted into the Raspberry Pi, you can power it on and con-
nect via SSH using a terminal from your computer or a remote client software, such as PuTTY
(https://www.putty.org/). You can connect to the Raspberry Pi hostname raspberrypi.local. If
there are issues, you can also connect to the our fixed Raspberry Pi IP addresses, which are set to
192.168.0.10, SSH port is 22. Please set your local network IP address to 192.168.0.1.
For more details and troubleshooting, refer to the official Raspberry Pi documentation:
https://www.raspberrypi.com/documentation/computers/getting-started.html
To setup Wifi when logged in via SSH use ’sudo raspi-config’ and enter System Options - Wireless
LAN.
sense = SenseHat ()
sense . show_message ( " Hello , ␣ Embedded ␣ AI ! " , text_colour =[255 , 0 , 0])
2/4
TH Deggendorf - Campus Cham Prof. Tobias Schaffer
sense = SenseHat ()
while True :
temp = sense . get_temperature ()
humidity = sense . get_humidity ()
pressure = sense . get_pressure ()
print ( f " Temp : ␣ { temp :.1 f } C ␣ ␣ Humidity : ␣ { humidity :.1 f }% ␣ ␣ Pressure : ␣ { pressure :.1 f } hPa
")
time . sleep (2)
3.2 Part 2: Arduino Nano 33 BLE Sense - IMU and Temperature Sensor
3.2.1 Step 1: Installing Required Libraries
Ensure the necessary Arduino libraries are installed:
1. Open Arduino IDE.
void setup () {
Serial . begin (9600) ;
while (! Serial ) ;
if (! IMU . begin () ) {
Serial . println ( " IMU ␣ initialization ␣ failed ! " ) ;
while (1) ;
}
3/4
TH Deggendorf - Campus Cham Prof. Tobias Schaffer
void loop () {
float x , y , z ;
if ( IMU . ac cele ratio nAva ilabl e () ) {
IMU . readAcceleration (x , y , z ) ;
Serial . print ( " Acceleration : ␣ X = " ) ; Serial . print ( x ) ;
Serial . print ( " ␣ Y = " ) ; Serial . print ( y ) ;
Serial . print ( " ␣ Z = " ) ; Serial . println ( z ) ;
}
delay (500) ;
}
Upload the sketch to the Arduino and open the Serial Monitor to observe acceleration values.
Also refer to the following website for Arduino Nano 33 Sense Rev2 documentation:
https://docs.arduino.cc/tutorials/nano-33-ble-sense-rev2/imu-accelerometer/.
void setup () {
Serial . begin (9600) ;
while (! Serial ) ;
if (! HS300x . begin () ) {
Serial . println ( " HS300 ␣ sensor ␣ initialization ␣ failed ! " ) ;
while (1) ;
}
}
void loop () {
float temp = HS300x . readTemperature () ;
float humidity = HS300x . readHumidity () ;
Serial . print ( " Temp : ␣ " ) ; Serial . print ( temp ) ; Serial . print ( " C ␣ ␣ " ) ;
Serial . print ( " Humidity : ␣ " ) ; Serial . print ( humidity ) ; Serial . println ( " % " ) ;
delay (2000) ;
}
Also refer to the following website for Arduino Nano 33 Sense Rev2 documentation:
https://docs.arduino.cc/tutorials/nano-33-ble-sense-rev2/humidity-and-temperature-sensor/.
4/4