Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T-deck trackball not working? #71

Open
asherevan opened this issue Jan 11, 2025 · 11 comments
Open

T-deck trackball not working? #71

asherevan opened this issue Jan 11, 2025 · 11 comments

Comments

@asherevan
Copy link

asherevan commented Jan 11, 2025

I am trying to read from the trackball in micropython, but the down direction seems to not work.
I am using this code:

from machine import Pin

pwr = Pin(10, Pin.OUT)
pwr.on()

tb_up = Pin(3, mode=Pin.IN, pull=Pin.PULL_UP)
tb_down = Pin(15, mode=Pin.IN, pull=Pin.PULL_UP)
tb_left = Pin(1, mode=Pin.IN, pull=Pin.PULL_UP)
tb_right = Pin(2, mode=Pin.IN, pull=Pin.PULL_UP)
tb_click = Pin(0, mode=Pin.IN, pull=Pin.PULL_UP)
tb_up_value = tb_up.value()
tb_down_value = tb_down.value()
tb_left_value = tb_left.value()
tb_right_value = tb_right.value()

def left():
    global tb_left_value
    if tb_left.value() != tb_left_value:
        tb_left_value = tb_left.value()
        return True
    else:
        return False

def right():
    global tb_right_value
    if tb_right.value() != tb_right_value:
        tb_right_value = tb_right.value()
        return True
    else:
        return False

def up():
    global tb_up_value
    if tb_up.value() != tb_up_value:
        tb_up_value = tb_up.value()
        return True
    else:
        return False

def down():
    global tb_down_value
    if tb_down.value() != tb_down_value:
        tb_down_value = tb_down.value()
        return True
    else:
        return False

def pressed():
    return not tb_click.value()

while True:
    time.sleep(0.5)
    print('Trackball up:', up(), " Trackball down:", down(), "Trackball right:", right(), " Trackball left:", left(), "Pressed:", pressed())

Any ideas?

Also it would be great if you uploaded micropython examples for everything.

@asherevan
Copy link
Author

Also I cannot get the SD card to work.

@lewisxhe
Copy link
Contributor

lewisxhe commented Jan 13, 2025

You forgot to set GPIO10 high.

//!⚠️ The board peripheral power control pin needs to be set to HIGH when using the peripheral

@asherevan
Copy link
Author

Oh. Sorry forgot to include that in the code. Updated.

@lewisxhe lewisxhe closed this as completed Feb 6, 2025
@asherevan
Copy link
Author

Is there a way to fix the SD card problem?

@lewisxhe
Copy link
Contributor

lewisxhe commented Feb 6, 2025

What happened to the SD card? I thought you had no problem.

@lewisxhe lewisxhe reopened this Feb 6, 2025
@asherevan
Copy link
Author

Oh. Sorry. I had added that in a later comment.
The micro SD card will not mount. I am using a SanDisk 32 GB MicroSD card and using this code:

import machine
import os
import sdcard

sdspi=machine.SoftSPI(-1, sck=machine.Pin(40), mosi=machine.Pin(41), miso=machine.Pin(38, machine.Pin.IN))
sd = sdcard.SDCard(sdspi, machine.Pin(39))
os.mount(sd, '/sd')
print('SD card mounted.')

But it randomly returns one of "OSError: no response from SD card", "OSError: timeout waiting for v2 card", or "OSError: [Errno 19] ENODEV" error.

@lewisxhe
Copy link
Contributor

lewisxhe commented Feb 7, 2025

The SPI bus is shared by the screen and LoRa. You need to set the SPI CS of the screen and LoRa to HIGH, then perform SD initialization, and set GPIO10 to HIGH. Like this example

//! The board peripheral power control pin needs to be set to HIGH when using the peripheral

@asherevan
Copy link
Author

Like this?

import machine
from machine import Pin, SoftSPI
import sdcard
import os

pwr = Pin(10)
pwr.on()

sdCS = Pin(39)
screenCS = Pin(12)
loraCS = Pin(9)

screenCS.on()
sdCS.on()
loraCS.on()

MISO = Pin(38, Pin.IN, Pin.PULL_UP)
sdspi=machine.SoftSPI(-1, sck=machine.Pin(40), mosi=machine.Pin(41), miso=MISO)
sd = sdcard.SDCard(sdspi, sdCS)
os.mount(sd, '/sd')

@lewisxhe
Copy link
Contributor

lewisxhe commented Feb 7, 2025

Yes, you try it.

@asherevan
Copy link
Author

I tried it but It still doesn't work.

@lewisxhe
Copy link
Contributor

lewisxhe commented Feb 8, 2025

Maybe you can try the Arduino code first to test whether the SD card is available. I am not familiar with Micropython.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants