Main Issue
When I build a project and upload it to Thumby (RP2040), I get Success in the terminal, while on Thumby I only see a black screen and nothing happens.
What I get with Arduino IDE build: working code like expected PlatformIO build: black screen and nothing happens, no code running I guess.
#include <Arduino.h>
#include <Thumby.h>
#include <Keyboard.h>
#include "ThumbyUtils.h"
#include "PhraserUtils.h"
#include "OnScreenKeyboard.h"
#include "TextField.h"
#include "Registry.h"
Thumby* thumby = new Thumby();
void setup() {
// Sets up buttons, audio, link pins, and screen
thumby->begin();
// Init duplex UART for Thumby to PC comms
Keyboard.begin(KeyboardLayout_en_US);
//TODO: Disable serial in the final version
Serial.begin(115200);
delay(1000);
Serial.printf("PSM-1 (Phraser)\n");
Serial.printf("Thumby (Pi Pico) USB Password Manager\n\n");
// Make sure RX buffer is empty
removeRxBytes();
drawLoadingScreen(thumby);
loadRegistryFromFlash();
initOnScreenKeyboard();
playMessageSound(thumby);
delay(1000);
playMessageSound(thumby);
delay(1000);
playMessageSound(thumby);
}
void loop() {
Serial.printf("PSM-1 (Phraser)\n");
// Clear the screen to black
thumby->clear();
keyboardLoop(thumby);
// Receive and display a message from link
receive(thumby);
// Update the screen
thumby->writeBuffer(thumby->getBuffer(), thumby->getBufferSize());
}
Sorry for the long reply.
You are right about versions, they are differs.
However, my friend doesn’t want to change his arduino IDE platform setup because he doesnt know for sure if this would work on the new version.
So I’m trying to setup all the things on PlatformIO + VSCode.
I am trying to test a simple project on Thumby to see if it works.
I got this code from official website:
// A simple example showing how to use main components of the Thumby Arduino C/C++ library
// This example depends on TinyCircuits' Thumby.h+ssd1306.h and GraphicsBuffer.h+font.h as well
// as the Arduino RP2040 board package by earlephilhower
#include <Thumby.h>
Thumby thumby = Thumby();
char sendBuf[7] = "Hello!";
uint8_t dataBuf[7];
uint8_t packedBuf[10];
// Removes all bytes from RX buffer (use after writing on Serial1)
void removeRxBytes(){
delay(10);
while(Serial1.available() > 0){
Serial1.read();
}
}
// Play a sound that sweeps a frequency range
void playMessageSound(){
for(uint16_t f=3000; f<10000; f+=250){
thumby.play(f);
delay(10);
}
// Stop the audio from playing forever
thumby.stopPlay();
}
// Send a message over link
void send(){
// If packing does not fail, send over Serial1
if(thumby.linkPack((uint8_t*)sendBuf, sizeof(sendBuf), packedBuf, sizeof(packedBuf)) != -1){
// Write on Serial1 (this this initialzed in the Thumby Lib)
Serial1.write(packedBuf, sizeof(packedBuf));
// Remove echoed RX bytes
removeRxBytes();
}else{
thumby.setCursor(0, 20);
thumby.print("Packing Error!");
}
}
// Get a message from over link
void receive(){
// If enough bytes in RX to fit packed message, read and try to unpack
if(Serial1.available() >= 10){
size_t read = Serial1.readBytes(packedBuf, sizeof(packedBuf));
if(thumby.linkUnpack(packedBuf, read, dataBuf, sizeof(dataBuf)) != -1){
thumby.setCursor(0, 20);
thumby.print((char*)dataBuf);
playMessageSound();
}else{
thumby.setCursor(0, 20);
thumby.print("Unacking Error!");
removeRxBytes();
}
}
}
void setup() {
// Sets up buttons, audio, link pins, and screen
thumby.begin();
// Init duplex UART for Thumby to PC comms
Serial.begin(115200);
// Make sure RX buffer is empty
removeRxBytes();
}
void loop() {
// Clear the screen to black
thumby.clear();
// Draw a message so the screen is not just black
thumby.setCursor(0, 0);
thumby.print("Thumby!");
// If A or B is pressed, send a message
if(thumby.isPressed(BUTTON_A | BUTTON_B)){
playMessageSound();
// Send a message over link
send();
playMessageSound();
thumby.setCursor(0, 10);
thumby.print("A/B Pressed!");
}
// Receive and display a message from link
receive();
// Update the screen
thumby.writeBuffer(thumby.getBuffer(), thumby.getBufferSize());
}
Unfortunately, when I’m trying to upload this code with Upload button I’m getting a black screen still.
But when my friend was building his overall project using ArduinoIDE and gave me the ulf2 file, I would just drop it on Thumby with the mouse - Drag’n’Drop, Thumby would restart on its own and everything would work.
So maybe I’m missing some setting.
Even after updating the core version, one can downgrade the core version to the old one if it doesn’t work. There is no risk.
I am thinking that’s not a main issue, because I’ve tried to upload a simple Thumby project and got the same result. Might be something in building settings
I see. Then it may experience a crash. Hard to tell without a debugger attached.
What definitely is problematic is the pin usagee. The library declares
but when SPI.begin() is done, the standard pins are used
So when code like
is executed, GPIO16 will be initialized with the GPIO function “SPI RX” (MISO) and regular digitalWrites() should not work anymore – the pin is being controlled by the SPI peripheral now. The SPI would have to be initialized in essentially a two-wire mode (just SCLK and MOSI/SDA) and leave all other pins alone.
Very intersting. If it works, you can remove the entire build_flags line to not get spammed with debug prints.
Still… someone would need to look at the library with the current core version and figure out a code fix for it to work. Kind of a shame that it doesn’t work with the newest core. It very likely is because of the SPI connections and code…