check in
Completed

USB Gravity 6D sensor designed for desktop computers

PROUSB Gravity 6D sensor designed for desktop computers

tag

96
0
0
0
Mode:Full

License

GPL 3.0

Creation time:2024-11-11 09:32:44Update time:2024-11-13 09:34:51

Description

USB acceleration gyro sensor

Everyone must be worried about the lack of gravity sensing on desktop computers. This USB acceleration and gyroscope sensor designed for the host can help you solve the problem!

The USB plugged into the rear of the chassis has:

  • Auto-rotate: Automatically rotate the screen when turning the case over;
  • Free fall detection: Automatically destroy data when the chassis is detected to fall, no worries;
  • Identify chassis fall: Your host seems to have fallen. Do you need help contacting you for repair?
  • Earthquake report: When an earthquake of magnitude 7 or above occurs, it will notify you with a delay of two seconds for prompt processing;

 

In order to prevent it from being wasted, some additional functions have been added to it, and it can be used as a USB development board:

  • Serial UART: The line sequence refers to the USB-to-serial port device. Writing USB-CDC firmware can be used as a USB-to-serial port;
  • RGB indicator light: nice to look at, but useless;
  • Two buttons: The default is for debugging and can be configured as a general button;
  • SD card slot: can be used as an extremely slow USB card reader;

Learn by handwriting the above function codes: USB-HID, USB-CDC, USB mass storage device.

 

Attached is the following (with code):

  • Air mouse: Gravity detection is mapped to the mouse, and the pointer moves with the direction of the device;
  • Connect to game engine: control 3D objects in real time;

Take a look at the video below for the part of operating the mouse and operating the game.

 

Hardware design

Based on the cheaper stc8h8k64u microcontroller and lsm6ds3tr sensor. The BOM of LC is about ¥14, and the BOM of a certain product is about ¥10.

Using the universal U disk form factor, you can use the ordinary U disk shell.

There is an SD card slot on the front, which conflicts with the buttons and indicators, so the buttons are on the back.

Hardware considerations:

1. When the P54 (NRST) pin is used as a reset pin, it has a built-in 4.1K pull-up and does not require an external pull-up. When used as a normal IO, just turn on the internal pull-up and omit the external pull-up resistor;
2. In order to ensure that the SD card does not malfunction when the microcontroller is reset, 47K pull-up resistors are added to all pins of the SD card, which remain high during soft reset and restart into ISP mode;
3. The RGB indicator light has a relatively large current-limiting resistor (10K because I think it is too bright), which can be appropriately reduced, otherwise it may be too dark;

PCB rendering

Real shot

Universal USB flash drive enclosure can be used!

Software included

The code in the attachment may not be updated, the software part:

Please visit github: https://github.com/lzyor/oshw-usb-gyro

  • Firmware-gyro-hid: Firmware code implements hid
  • Py-air-mouse: python reads data and simulates mouse
  • Rs-bevy-3d-view: rust implements simple filtering and 3D interface demonstration

 

Screenshot

Operate the balancer game, simulating a mouse.

Connect to 3D game engine to calculate spatial angles.

Firmware-gyro-hid Firmware code firmware-gyro-hid

To simply implement a usb-hid driver-free device, please modify the descriptor file yourself.

Based on the sdcc4.4 compiler, please pay attention to syntax and byte order issues when transplanting to keil.

Contains usb-hid code and lsm6ds3tr driver. Please refer to the bsp.c and bsp.h files for peripheral and pin configuration.

# clear
make clean
# compile
make
# The output is located in bin/main.ihx

The default operation is 24MHz , and the reset pin is used as reset. The firmware code detects the DL button and automatically resets to usb-isp download mode when pressed. Both buttons can be configured for general purpose use.

py-air-mouse Simulate mouse py-air-mouse

Sample code, no filtering, python accesses the device and reads sensor values, and simulates mouse operations to implement the "air mouse" function. Obviously, the firmware can also be modified to implement a hardware mouse. The code here is a software simulated mouse.

Based on the hid package, the simulated mouse is based on the pyautogui package.

# pip install hid
# pip install pyautogui
./main.py

rs-bevy-3d-view Demo 3D model rs-bevy-3d-view

Sample code, using rust to read sensor values ​​and simple filtering, bevy 3D engine restores the rotation angle of the device using a 3D model.

Angle mapping and filtering are very crude and require modification for practical applications.

The 3D model of the PCB is saved in the material folder.

# rust minimum version 1.75
cargo run

---

Updated station B video: https://www.bilibili.com/video/BV1uM4m1R7bB/

Designed by Lzyor (from OSHWHub)

Link:https://oshwhub.com/lzyor/oshwhub-usb-acc-1

Design Drawing

Download File
The preview image was not generated, please save it again in the editor.

Attachments

OrderFile nameDownload times
1
out-low.mp4
31
2
oshw-usb-gyro-main_2024-03-29.zip
67
Add to Album
0
0
Share
Report

Comment

All Comments(1)
Sort by time|Sort by popularity
Followers0|Likes0
Related projects
Empty

Bottom Navigation