PicoWheel: a DIY racing wheel, with accelator, brake and Up-Down gear

What is this?

This is a racing wheel, that has foot pedals for accelator and brake and can work on any game as long as it supports an Xbox360 controller.

What is it made of?

This Racing wheel was made using parts lying around in my home ( Except the foot pedal, i bought them but they are very cheap) . The Pico Wheel runs on a Raspbery Pi Pico, the rotation of wheel is interphased by Potentiometers. The Code is written in Circuit Python. Refer to https://hridaybarot.home.blog/2021/01/31/using-raspberry-pi-pico-has-hid-device-to-control-mouse-and-keyboard/ to get the HID library and setup Circuit Python.

Schematics

IMPORTANT: The Buttons numbers aren’t the same as the once refrenced in the code. Button number in the picture above are to only highligh where I attached buttons on PicoWheel

Calibration:

The code is given below. First read through all the comments. Undestand the Calibration-debug process. Then save it as “code.py” on your pico.

Then Run it. Perform CALIBRATION TEST 1.

Got to the Top of the code and change “debug” to True. Save it as “code.py” and run it. Close the editor and Perform “Set-Up on PC”

https://github.com/hriday111/picoWheel/blob/main/code.py

Set-Up on PC

Get the app called X360ce at https://www.x360ce.com/. Install it, run it as Administrator.

Click “add”

Click on “CircuitPython HID” device, then click add selected device.

On this page:

Click the right trigger, press accelator. Do the same with left trigger and press brake.

Put your cursor on the left joystick

and click the left arrow, then move your wheel towards the left.

Then set up your gear up and down. Simply click any button on gamepad and press that button on your wheel. EXCEPT the OFFSET Buttons.

Fire up your game and YOU are good to go.

Feel free to contact me if there are any mistakes or you need any help. For immideate help contact me at hridaybarot1@gmail.com

Screen Reactive LEDs

Introduction

As you must have seen in the video above that the lights behind my speaker react to what’s going on my screen. The lights change colors based on the color of the edges of my screen. How? Let’s get started with what is needed for the project.

Parts Needed

  • Arduino Uno
  • 2RGB LEDs or Strips.
  • Arduino IDE setup arduino.
  • And Python Set up and running.

You can pretty much get and arduino uno or nano for very cheap if you buy the clone version. If you wish to buy the real version it costs around 20USD.

RGB leds are super cheap. You can get a hundreds of them for 9USD here.

Here is a quick start guide on how to setup Python and Pip. Once you have followed the steps. Do the followind steps:

  1. Open CMD: Press Win+r and type CMD (Windows users only); For mac user, search “terminal” on your serach bar. And for Linux users, you’ll know what to do.
  2. Make sure you have pip, but typing: pip in the cmd or terminal. You’ll see a hude range of options like install , uninstall , freeze, etc. That means you have pip.
  3. Next type: pip install pillow.
  4. Then: pip install pyserial
  5. The finally type: pip install keyboard

Download and setup the Arduino IDE software here. This link is necessary if you don’t know how to upload the code to arduino uno.

So now we have the requirements, what now?

Coding

This is the fun part. I’ll link The github repo and then let’s go over the code together.

https://github.com/hriday111/Screen_reactive_LED

The folder in the repo called “ard” the the arduino code for the hardware required, and “main.py” is the the python code. The PC and Arduino Uno communicate through USB. The python code must be run on the PC and the arduino code uploaded to Arduino using the IDE.

Let’s go over the arduino code first:

Before you upload the code, keep note for the PORT number. For windows users it will be COMx, where x is the com number.

The code is pretty self explanatory. It arduino takes input through usb. The input should be in the format: {LED ID}{ }{LED BRIGHTNESS}

For the LEFT side led, r , g or b for the left, red green and blue leds and x y z for the right, red green and blue LEDs.

After typing the LED ID type a space and the {BRIGHTNESS VALUE}, which should be from 0-255.

Now let’s go over the python code:

#Here we import all the libraries  
import keyboard #A library to check for keyboard input.
import time #Time library for, well, time managment
import ctypes 

import PIL.ImageGrab # the pillow library for color detection
from keyboard import is_pressed
import winsound 
import time
import serial #LIB for communicating with Arduino.
import sys

These were the above libraries that are needed for the program to run smoothly.

The code in the While loop is the main part.

It captures the screen and crops it from (0,0) to (the height of the screen, 20) so it will capture the left side of my screen and store the rgb value of each and every pixel in a list. Then it checks which rgb value was most repeated and sends that value to the arduino in the format I mentioned earlier.

Conclution

I got inspired by this project from philips HUE. I tried looking up other people who had done the project but couldn’t find any and so I decided to make my own.

Thank you for reading.

~Hriday Barot

Controlling Asphalt 8 with hand gestures, using mpu6050 and raspberry pi pico

Okay so what is this?

Well if you saw the video then I made a way to control almost any game, in this case “Asphalt 8: Airbone” , with just my hand. So if I tilt my hand forward, left, right or back the car in the game with accelerate, turn left, turn right and deaccelerate respectively.

How did I do this?

I simply used a raspberry pi pico with circuit python connected to a mpu6050. The mpu6050 is a module the outputs acceleration and gyroscope. The pico then reads those outputs from the module and makes it usable for controlling a game.

How do you get started?

First here is a list of thing you need:

  • Raspberry pi pico (4USD )
  • Mpu6050 (~2 USD)
  • Jumper Wires

Secondly you need to get circuit python on the Pico. To do that you simply need to download the uf2 provided from the link below, then press the BOOTSEL button and connect your pico to the pc (while pressing it) and copy the uf2 file to the pico and disconnect you pico.

Download here

Next you’ll need to connect the mpu6050 to the pico. To do that you will need 4 jumper wires. Connect:

GP15 and GP14 are the last pins on the left side of the raspberry pi pico.

After doing so, connect your pico to your pc (you must have thonny configured)

The code is provided below:

import time
from math import atan2, degrees
import board
import busio
import adafruit_mpu6050
from adafruit_hid.keyboard import Keyboard as kbd
from adafruit_hid.keycode import Keycode
i2c = busio.I2C(board.GP15, board.GP14)
sensor = adafruit_mpu6050.MPU6050(i2c)
import usb_hid
Keyboard=kbd(usb_hid.devices)

kw=Keycode.W
ka=Keycode.A
ks=Keycode.S
kd=Keycode.D

k_nitro=Keycode.SPACE
# Given a point (x, y) return the angle of that point relative to x axis.
# Returns: angle in degrees


def vector_2_degrees(x, y,l=False):
    if l:
        angle = degrees(atan2(y, x))
    else:
        angle = degrees(atan2(y, x))
    if angle < 0:
        angle += 360
    return angle


# Given an accelerometer sensor object return the inclination angles of X/Z and Y/Z
# Returns: tuple containing the two angles in degrees
t=""
f=""
def get_inclination(_sensor):
    x, y, z = _sensor.acceleration
    return vector_2_degrees(x, z,True), vector_2_degrees(y, z), int(x),int(y),int(z)


x,y,z=0,0,0
def press(key):
    Keyboard.press(key)
def release(key):
    Keyboard.release(key)
turn=None
ac=None
toA=None
#l=[None,None]
while True:
    try:
        turn, ac,x,y,z = get_inclination(sensor)
        turn=int(turn)
        ac=int(ac)
    except:
        pass
    #print(turn,ac,x,y,z,sep=" : ")
    
    if turn<50:
        if t=="r":
            Keyboard.release(kd) #leave r
        print("left")
        Keyboard.press(ka)
        #l[0]=ka
        t="l"
    elif turn>130:
        if t=="l":
            Keyboard.release(ka) #leave l
        print("right")
        Keyboard.press(kd)
        #l[0]=kd
        t="r"
    else:
        if t=="l":
            Keyboard.release(ka) #leave l
        elif t=="r":
            Keyboard.release(kd) #leave r
        l[0]=None
    
    if ac<50:
        if f=="f":
            Keyboard.release(kw) # leave f
        print("brake")
        Keyboard.press(ks)
        #toA=ks
        f="b"
    elif ac>120:
        if f=="b":
            Keyboard.release(ks) #leave b
        print("accel")
        Keyboard.press(kw)
        #toA=kw
        f="f"
    else:
        if f=="f":
            Keyboard.release(kw) # leave f
        elif f=="b":
            Keyboard.release(ks) #leave b
    
    
    if z >=11:
        print("nitro")
        Keyboard.send(k_nitro)
    
    
    
    
    time.sleep(0.000001)

What is basically happening in the code is I am getting raw values from the module mentioned above and converting them using atan2() into inclination. I am used those converted values to get the tilt(foward, left, right or back) and then sending keyboard keys respectively.

Lastly I am using intertia on the Z axis to get the gravity. So if the gravity value increases “nitro” is activated.

Conclution

What next? Theoretically, we can share the laptop screen to a vr like google cardboard or oculus rift and play asphlat 8 in vr which is controlled by hand. I’ll make an update on it.

Voice Assistant Extention for “Smart Table”

The code links are at the bottom.

The Smart Table shown in the prevous post was quite nice, but it was something for “fun” and not something I can use for my day-to-day life.

I had an idea. I always had trouble in some of my lessons, especially 2nd and 3dh language lessons in school. I did not know the meanings of a lot of things, and it was always a trouble to translate it every 5 mins. So i though that I should make a simple voice assistant that would just translate sentences to a desired language.

I had done this previously when I made a messenger bot , which was quite impractical for a 1 to 1 conversation, but if the bot added in a group was very helpful. It was a hobby project. one of the functions it offered was “translate”, all you had to type to the bot was “\translate <text> <destination_lang>” for e.g. “\translate this is a pen polish.”

I just had to do something pretty similar.

So first I used the voice recognition library for python and initialized it. Then stored the text it listened from the mic to variable <string> with name “cmd”.

then i used an if statement to check if, what i said started with “translate”. If it did, I saved the text after “translate” to a variable , then i took the last word from the orignal text i said, which would be a language name. Then i’d delete the last word from the toTranslate Variable as that was the language name.

if cmd.startswith("translate"):
    toTranslate=cmd.split("translate ",1)[1]
    toLang=cmd.split()[-1]
    toTranslate=seperator.join((toTranslate.split(" ")[:-1]))

I just passed the toTranslate and toLang variable to the “translate” library.

The next problem I encountered was that I was not able to use my mic in 2 places (the script and my online lessons) and if i did try to use it, the script would be prioritized and it would turn of my speakers off also. So using a wake word was also out of the window as that required constant mic attention.

So what I did was , i had a infrared sensor and attached it to the bottom of my Desk, so I can use my leg as a trigger to activate the voice assistant and so my speakers won’t work only for a second or two. I attached it to my arduino.

sensor not triggered
sensor triggered
The Arduino of the Smart Table.

So that was done, it was very easy, i thought i might as weel add a few more functions.

So these are the funtions I added:

  • Google Search
  • Website open
  • Synonym finder
  • English Dictionary
  • Calculator
  • Smart Table Led Color changer (supported colors are : red, blue, green, magenta, yellow, and cyan)
  • a simple repeat afte me
  • and a “close tab” function , which would emulate CTRL+W .

These were all that I needed. And I just use if/elif/else statements as the functions had to be limited and an ML model would be overboard and impractical.

Currently I am working on more fuctions that would automate a few things.

The link to the code: https://github.com/hriday111/Arduino_Smart_Table

Arduino Smart Table

I recently made a table which had and rgb auto-color changing ambilight. Then I had another Idea to make the lights music reactive. But sometimes I wanted a constant color , which does not change. It was good, but quite impractical, as I had to reupload the code everytime to the Arduino and it was quite a hastle.

So I got a solution. I used a push button to toggle through different modes of the light. The ambilight mode looked like this:

The color was not constant , it changed smoothly. The rgb strip was a 8 bit version, meaning that 3 colors , with intensity of 0 to 255, make upto 16,777,216 (which is 256 ^3). Why so many colors? let’s say the rgb value is (255,255,255) which is white, but if i make it into (255,255,254) the LED appears white but it is an entire different color.

I later added a bluetooth module and made a mobile application for my music reactive light mode.

The only problem with this was that I had to use my PC and run a python script to make it of use.

I don’t know much java or kotlin programming to make an app for android, but a website called kodular makes it easier, it provides block-programming, which is generaly not a good idea for huge projects, but as this was a support app, so i used block programming.

It had the same features as the python script with additional support for data-transfer-over-bluetooth speed control and mic sensitivity control.

The app was very simple looking, infact way to simple, and it would look better if it was done with Android Studio, but it did not seem worth the time to learn a completely new programming language.

The connect button is for connecting to the smart table and the start and stop button are for toggling the state of the lights, data-transfer, and microphone use. The MAX_OUT slider is for sensitivity and CLOCK_INTER is data transfer speed in milliseconds, with 1 being the fastest.

The Schematics are:

The led shown in the picture is a cathode rgb-led, and a rgb led strip would also work , The led strip “ws2812b” won’t work as that is an individual addressible led strip, whereas mine isn’t.

I will write another post on this as I have made one major extention that makes this Smart Table “Smart”. I will also upload the code.

Design a site like this with WordPress.com
Get started