Skip to main content
Version: FILS English

Rust Desk Assistant

An assistant that helps you focus and keep a good posture when working at a desk while keeping track of some environmental metrics. It comes equipped with the option of setting a timer.

info

Author: Voicea David-Alexandru

GitHub Project Link: https://github.com/UPB-PMRust-Students/project-VoiceaDavid

Description

This desk assitant is build using a Raspberry Pi Pico 2W, a humidity and temperature BME280 sensor, an ultrasonic HC-SR04 sensor, an SPI OLED module, two push buttons and a buzzer. The recorded data is sent to the computer via WIFI.

It will record some environmental data (temperature and humdity) from the space the user uses to work from. It also scans the user's position at the desk and in case it changes by a specfic margin, the user will be notified by a buzzer to fix his posture. In case the user wishes to focus on working for a specific time, a timer function is implemented (it is controlled by two push buttons).

Motivation

I always spend long hours at my desk, whether that is for work or entertainment purposes it varies. The idea is, I would like to have a device that can tell me when I am getting too close or too far from the screen, so I can avoid a bad posture or eye damage. In addition I would like this device to be able to record in real-time the humidity and temperature of my environment, so I know if the space I am using is suitable for long working hours. It would be nice to be able to set a timer on it too.

Architecture

Schematic Diagram

The diagram of the project:

Schematic

Raspberry Pi Pico 2W

  • Role: Controls and powers every component. It also gets readings from the sensors and displays them on the OLED module, it acts as the core component of the entire project.
  • Connections: GPIO for buttons, the buzzer and the HC-SR04 sensor. SPI for the OLED module and BME280 sensor.

BME280 sensor

  • Interface: SPI
  • Role: Reads environmental data (humidity and temperature) and sends them back to the pico.
  • Connections: conected to the Raspberry Pi Pico 2W, SDO -> SPI1 RX, CSB -> SPI1 CSn, SCK -> SPI1 SCK, SDI -> SPI1 TX, Vcc -> 3V3(out), GND -> GND

SPI OLED module

  • Interface: SPI
  • Role: Displays the environmental data and alerts if the user gets too close to the HC-SR04 sensor.
  • Connections: Vcc -> 3V3, Gnd -> Gnd, D0 -> SPI0 SCK, D1 -> SPI0 TX, RES -> GP20, DC -> SPI0 CSn, CS -> SPI0 RX.

HC-SR04 sensor

  • Interface: GPIO
  • Role: Detects the distance between the user and the desk assistant.
  • Connections: Gnd -> Gnd, Trig -> VBUS, Echo -> GP7 (but using a voltage divider so we're only sending 3.3V to the pico instead of the 5V the VBUS outputs), Vcc -> GP6.

Buzzer

  • Interface: GPIO
  • Role: Used as an alert for when the user gets too close to the screen or the timer runs out.
  • Connections: GP5.

Buttons

  • Interface: GPIO
  • Role: Used to increment/decrement the timer by 1 minute.
  • Connections: GP22 and GP26, each having a 5.1kOhm resistor in series

Log

Week 5 - 8 May

I souldered the pins on the picos and on the BME280 sensor at the laboratory and flased the debugger and connected it to the other pico.

picture_from_lab picture_connection_not_full

Week 6 - 11 May

I connected an LED to the pico and made sure everything works smoothly.

picture_led

Week 6 - 12 May

I managed to connect the SPI module to the pico and got it displaying some hardcoded messages.

picture_oled

Week 6 - 14 May

I connected and got the HC-SR04 sensor working and after many failed attempts it displays the correct distance until the closest object. At this time no connection in the code between the components was made. I was just making sure everything is wired properly and is working as intended.

picture_hcsr

Week 6 - 15 May

During the laboratory I finally connected the BME280 sensor and got it working. Until now it just stayed on the breadboard without being wired to anything. I was surprised to see it working on my first attempt, after having struggled with the HC-SR04 for around two days. (The picture is from the lab)

picture_bme280

Week 7 - 19 May

After taking a few days' break I got back into work with a simple task at hand: make the components communicate with each other. I had trouble making the buzzer work, as I had used a piezo buzzer until now and it just hated me. I ordered another passive buzzer and until it came I just ignored the piezo buzzer. Other than that, making the sensors communicate with the screen was not that difficult, and now I have actual relevant data being displayed. I also connected the buttons.

picture_measurements

Week 7 - 22 May

The hardware part was completed a few days ago, but I needed my new buzzer and unfortunately I was not able to get it until now. Other than that, I wrote some code for the HC-SR04 sensor, so that if an individual changes his/her position after powering the desk assistant with more than 5 cm, the device will consider this a 'bad posture' and will display a message on the screen. When this happens, the buzzer should also be buzzing, but I have yet to aquire the necessary buzzer.

picture_todate

Week 8 - 28 May

I aquired the buzzer I was talking about previously and connected it and made it work in the code too. It starts buzzing when the user gets too close or too far from his/her initial position.

picture_buzzer

Hardware

I've used two Raspberry Pi Pico 2 W's, a BME280 sensor to detect the humidity and temperature of the environment, a HC-SR04 ultrasonic sensor to detect the distance to the closest object, an SPI OLED module to display the values, a timer and the necessary messages when the posture of the user changes, 2 buttons setting the timer and a buzzer to attract the user's attention.

picture of hardware current state

Schematics

picture of schematic

Bill of Materials

DeviceUsagePrice
2x Raspberry Pi Pico 2WThe microcontroller[39.66 RON]
HC-SR04 Ultrasonic SensorDetect distance from the device to the user6.49 RON
BME280 SensorReads the environments' temperature and humidity73.99 RON
SPI OLED moduleDisplays the data23.79 RON
Passive BuzzerUsed to notify the user0.99 RON
2x Buttons6x6x6Increment/Decrement timer2x0.36 RON
3x 5.1k ResistorUsed for the buttons and for the voltage divider3x 0.10 RON
1x 2.2k ResistorAcceleration and breaking buttons1x 0.10 RON
10x 10cm Female-Female wiresMale-Female Wires4.88 RON
10x 20cm Male-Female WiresMale-Female Wires2.36 RON
40x 10cm Male-Male WiresMale-Male Wires4.99 RON

Software

LibraryDescriptionUsage
embassy-rpRP2040 peripheral accessInitializes and interacts with Pico W hardware peripherals
embassy-executorAsync runtimeRuns asynchronous tasks like motor control and input reading
embassy-timeTime utilitiesUsed for delays, scheduling, and task coordination
embassy-netNetworking stackManages TCP/IP over Wi-Fi; used for remote control
embassy-lab-utilsPico W Wi-Fi helpersSimplifies Wi-Fi and network stack setup
gpioGPIO moduleControls the buttons' and buzzer's pins
ssd1306Driver for SSD1306 OLED displayControls the SPI module
embedded_graphicsUsed to render shapes and textDisplays text on the SPI module
hcsr04_asyncCrate for the HC-SR04Used for getting the data from the object detection sensor
defmtLogging frameworkFor debug messages via RTT/serial
panic-probePanic handlerHandles panics with minimal overhead
static_cellStatic memory allocationSafely manages statically allocated Embassy resources
  1. Ultrasonic Distance Sensor Tutorial
  2. More about the ultrasonic sensor
  3. Inspiration for connecting and coding SPI Module
  4. Very helpful information and examples