0% found this document useful (0 votes)
17 views6 pages

Use A Joystick With Your Raspberry Pi Pico! - Science Electronics Fun!

The document provides an overview of various projects and tutorials related to science and electronics, focusing on microcontrollers, robotics, and programming. It includes specific examples such as using a Raspberry Pi Pico with a joystick and programming FPGAs. The content is structured to encourage exploration and experimentation in electronics and programming.

Uploaded by

Renba Renbler
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views6 pages

Use A Joystick With Your Raspberry Pi Pico! - Science Electronics Fun!

The document provides an overview of various projects and tutorials related to science and electronics, focusing on microcontrollers, robotics, and programming. It includes specific examples such as using a Raspberry Pi Pico with a joystick and programming FPGAs. The content is structured to encourage exploration and experimentation in electronics and programming.

Uploaded by

Renba Renbler
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Science Electronics Fun! An adventure into the world of science and electronics! Buckle up!

Home
PIC microcontrollers
The p18f45K20 Demo Board!
R232 Communication uPIC
PIC micro controller LCD project
PIC USB Programming
dsPIC33EP256GM710
u8051
TIL 311
Introduction to I2C with the C8051F410
I2C EEPROM Project with the C8051F410
Expand your mind, and I/O ports! MCP23017 IO Port Expander! Presto, Expando!
STM32 MCUs
STM32 — bare chip example (STM32F042F6)
Robotics
Endstops/Limit Switches
Checking the accuracy of a motor encoder
Lab set up
Workbench
PCBs
PLDs
Programming the XC9572XL: A tutorial
FPGAs/SoCs
Zynq 7000 SoC: Digilent CORA Z7
Programming Digilent Cora 7Z via JTAG Interface
Spartan 3A FPGA
Microblaze core on Breadboarded Spartan 3A [XC3S200A-4VQG100C]
Programming the Terasic DE10-Lite board (Altera FPGA) with Quartus
Lattice ICE40UP5K-SG48 from the bare chip!
A CPU Core for your WebFPGA!
Breadboarding a Spartan 7 series FPGA
Specialty Chips
MCP2221 – Add USB to your MCU!
Raspberry pi pico
Raspberry pi pico – Knight Rider LED effect
Use a joystick with your raspberry pi pico!
CONTROLLING GIKFUN DC MOTOR WITH RASPBERRY PI PICO
Rasperry Pi Pico – Operate Baomain Pneumatic Cylinder SC 32-200
Games
Make your own game of Brick-O-Blox (Tetris clone)

TOPICS  USE A JOYSTICK WITH YOUR MORE


RASPBERRY PI PICO!

At some point, you may want to


connect a joystick to your pi pico
to read position. One option is
Digilent’s PMod Joystick 2,
which communicates through
SPI. Fortunately, it is very easy
to set up SPI communication on
the rasperry pi pico!
Wiring up a stepper motor driver!

1 import machine
2 import utime

3 import ustruct

4 import sys

5 from machine import Pin

6
7 #PMOD2 Joystick

8 #4 pins

9
10 led_up = Pin(13, Pin.OUT)

11 led_down = Pin(15, Pin.OUT)

12 led_right = Pin(12, Pin.OUT)

13 led_left = Pin(14, Pin.OUT)

14
15 led_up.value(0)

16 led_right.value(0)

17 led_down.value(0)

18 led_left.value(0)

19
20 cs = machine.Pin(17, machine.Pin.OUT

21
22 spi = machine.SPI(0,

23 baudrate= 10000,

24 bits = 8,
25 firstbit=machine.S
26 sck=machine.Pin(18

27 mosi=machine.Pin(1

28 miso=machine.Pin(1

29
30 def getPosition(spi, cs):

31 msg = bytearray()

32
33 msg.append(0xC0)

34 msg.append(0x00)

35 msg.append(0x00)

36 msg.append(0x00)

37 msg.append(0x00)

38
39 cs.value(0)

40 spi.write(msg)

41 cs.value(1)

42
43 utime.sleep_us(25)

44
45 cs.value(0)

46 spi.write(msg)

47 data = spi.read(5)

48 cs.value(1)

49
50 return data

51
52 while 1:

53
54 data = getPosition(spi, cs)

55 print (data)

56 print (data[0])

57 print (data[1])
58 if data[0] > 225:

59 print ('RIGHT')

60 led_right.value(1)

61 else:

62 led_right.value(0)

63
64 if data[0] < 50:

65 print ('LEFT')

66 led_left.value(1)

67 else:

68 led_left.value(0)

69
70 if data[1] > 225:

71 print ('DOWN')

72 led_down.value(1)

73 else:

74 led_down.value(0)

75
76 if data[1] < 55:

77 print ('UP')

78 led_up.value(1)

79 else:

80 led_up.value(0)

81
82 utime.sleep(0.05)

83

PmodJYSTK2_pi_pico.py hosted with view raw


by GitHub

Science Electronics Fun! © 2024. All Rights Reserved.
Powered by  - Designed with the Hueman theme

You might also like