|
|
2 months ago | |
|---|---|---|
| .. | ||
| projects | 2 months ago | |
| README.md | 7 months ago | |
| boot.py | 9 months ago | |
| keyboard.py | 9 months ago | |
| keyboard_test.py | 9 months ago | |
| sdcard_test.py | 9 months ago | |
if wifi settings are set in settings.toml, the cardputer is accessible via the ip address shown in the top bar of the repl (might need to disable any infinitely running code to see it, or boot into safe mode.)
at the time of writing the ip address is 192.168.0.92 but this can easily change. also, if there are any other circuitpy wifi devices, they will need to be using a different port (or this one will) either way, default is 80 and any different may have to be specified to work. e.g. 192.168.0.92:1337 if using port 1337.
CIRCUITPY_WIFI_SSID = "SSID"
CIRCUITPY_WIFI_PASSWORD = "PASSWORD"
CIRCUITPY_WEB_API_PASSWORD = "passw0rd"
CIRCUITPY_WEB_API_PORT = 80
if the board is removed from usb without safely ejecting, the next time it is tried to use it enters read only mode. it seems a full restart (power off) is the only way to get it out of the read only state.
the code snippet is here , to read key codes. some day i will write a full map for easier coding.
while True:
print(hex(ord(sys.stdin.read(1))))
this produces a hex value such as 0x35 (key number 5). every key stroke including fn, shift and ctrl, produces a different result, as long as it is shown on the sticker it has a unique hex value, so its relatively trivial to implement into a project.
I am developing a library that decodes the codes. Check it out here
With that, simply use the following code to type text into the terminal. Expand it to your needs!
from keyboard import Keyboard
keyb=Keyboard()
while True:
print(keyb.scan(), end="")
currently keymaps are organised into the type of thing they are. the number row is conveniently indexable. the rest are dictionaries for easy lookup.
should it be saved in both directions for when you have the code but you dont know what the key is? I think there are Python ways of doing it in reverse, unless it is noticeably slow on a small device like this.
Some key combinations produce two codes in quick succession - the FN + Direction keys are a good example of this. Need to run experiments to figure out how to isolate these codes accurately. Also, some codes don't seem to properly register? OPT + D being a combination that I couldn't get the code to work for, even though that is what the Serial registers.
need to put this code in github, but for now it's here
import board
import busio
import sdcardio
import storage
spi = busio.SPI(board.SD_SCK, MOSI=board.SD_MOSI, MISO=board.SD_MISO)
cs = board.SD_CS
try:
sdcard = sdcardio.SDCard(spi, cs)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd") # access files on sd card here
except OSError:
pass # SD card not inserted/found
then, for example
with open("/sd/data.txt") as f:
lines = f.readlines()
Currently, there seems to be an issue with CircuitPython filesystem being readonly, making it impossible to write files. Opening a file as "w" produces an OSError.
FIXED: CircuitPython prevents both device and user from writing to the device at the same time over USB, since this can cause problems, corruption etc. A workaround is using the boot.py file to alternate between read/write access using a pin grounding. Adafruit has an explanation but their instruction is unclear for Cardputer specifically.
This Github user wrote a boot.py file that works for the Cardputer. This is a necessary addition to the root drive if you want to be able to write files to the drive or the SD card. I have a version of this file saved here, without the PyDOS specific comments/print statements.
address is 0x21
Need to be able to read (and write in some cases) to registers as outlined in the Not achieved anything useful with the qr code scanner/i2c in CircuitPy yet