Tag Archives: raspberry

Started working on C64Pico with Bigred

A week ago I got the last components delivered to my doorstep.

This project was made by Silvervest and it’s f*ckin awesome.

https://github.com/silvervest/c64pico

I was afraid to start this myself, SMD is on another level for me.
But my good friend Marco said … No problem!

So I ordered components online, which was not easy.
Selecting the correct parts, sizes and options.

These things are really really small

Using tweezers to place the components was even difficult.
The slippery tiny bastard got catapulted everywhere. (Or got stuck on fingers, soldering iron and alike)
Many small components got lost into the 7th dimension. Never to be found again.

Awesome to work on this together, but Marco said that I have to try it myself.
Welllll, I got 3/4 of the ATmega328PB-A perfectly soldered, then I notished that it was crooked.
Desoldering was a mess, and I heated the PCB TOO much with the heatgun.

My messed-up PCB, and f*cked-up IC. Leave it to the professionals.

Next step for me is soldering the 75 mini buttons!

Got a Trinitron display from him, I was looking for this for a long time.

What to do when waiting for your ribs on the smoker. (Programming some python)

This time I used a rub with the following ingredients:
Seasalt, garlic, brown sugar, mustard seeds, paprica, cilantroseeds, black pepper, red pepper, oregano, thyme and cumin.

Doing a simple 3-2-1 smoke session, so .. what to do in dose 6 hours?

Lets make something using a Sense hat and Python.
Same HAT I used for my xmas ornament thingy in our tree.

  • Generate a large maze (80×80 for now)
  • Paint the maze using colors on the SenseHat
  • Read joystick movement and scroll the maze accordingly, keeping the player in the middle

Now I have to paint my ribs with BBQ sauce, and leave it in the smoker for yet another hour. (Nice glazing)

Next steps for the maze:

Use a better way to generate (reverse backtracking as I made for my other maze thing)

Wall collision detection is nearly completed.

Better placement “birth” of player in the maze.

# # # # # # # # # # # # # # # # # # # # 

# R D . . . . . R D . . . . R R D R D # 

# D L . . . . . U D . . . . U . R U D # 

# D . . . . R R U R D . . R U U L . D # 

# R D . . . U . . . R R D U . . U L D # 

# . R D R R U . . . . . D U . . . U L # 

# . . D U L . . . . . D L U . . . . . # 

# . . R R U . . . . . R R U . . . . . # 

# . . . . . . . . . . . . . . . . . . # 

# . . . . . . . . . . . . . . . . . . # 

# . . . . . . . . . . . . . . . . . . # 

# . . . . . . . . . . . . . . . . . . # 

# . . . . . . . . . . . . . . . . . . # 

# . . . . . . . . . . . . . . . . . . # 

# . . . . . . . . . . . . . . . . . . # 

# . . . . . . . . . . . . . . . . . . # 

# . . . . . . . . . . . . . . . . . . # 

# . . . . . . . . . . . . . . . . . . # 

# . . . . . . . . . . . . . . . . . . # 

# # # # # # # # # # # # # # # # # # # # 

New part demo (st7789 with micropython)

(And some WIP)

A little starfield demo

followup on : https://www.henriaanstoot.nl/2024/01/26/raspberry-pico-with-st7789v2-display-3d-control/

Some other stuff

See links below

The smoking monitoring thingy is a new version of my (never posted) BBQ watch.

Raspberry Pico with st7789v2 display 3D control

While ordering components for a mini C64 project I’m doing with my friend Bigred, I ordered a cheap ST7789-v2 display.

I want to make a generic pico gadget with a display, buttons and sound.
This to make a mini device for writing micropython demos.

The 3 tactical buttons are controlling the X,Y and Z axis of the rotating Cube.

Pinout:

PICODISPLAY
GP2Tactical switch (other side to 3v3)
GP3Tactical switch (other side to 3v3)
GP4Tactical switch (other side to 3v3)
GP9CS1
GNDGND
3v3VCC
GP18SCL (SPI clock)
GP19SDA (MOSI / SPI Data)
GP20RES (reset)
GP17DC (data command)
GP16BLK (backlight)

I know it says SCL/SDA (i2c) but it’s SPI controlled.

Used library : https://github.com/russhughes/st7789_mpy/tree/master

Some 3D explanation I drew a long time ago.

Using python you can use the Math funtions. (sin/cos)
Note: these are in radians!
print(math.sin(math.radians(30))) # 30 degrees

When using MachineCode you can use lookup tables.
These are generated tables which hold precalculated sin data for every degree.
You don’t have to use both cos and sin! (these are just 90 degrees shifted!)

Erik and I used a little basic program to generate an ASM include file like this

Costab LABEL BYTE
DB 0B4h,0B4h,0B4h,0B4h,0B4h,0B3h,0B3h,0B3h,0B2h,0B2h,0B1h,0B1h,0B0h,0AFh,0AFh
DB 0AEh
DB 0ADh,0ACh,0ABh,0AAh,0A9h,0A8h,0A7h,0A6h,0A5h,0A4h,0A2h,0A1h,0A0h,9Eh,9Dh,9Bh
DB 9Ah,98h,96h,95h,93h,91h,90h,8Eh,8Ch,8Ah,88h,86h,84h,82h,80h,7Eh
DB 7Ch,7Ah,78h,76h,74h,72h,70h,6Eh,6Ch,69h,67h,65h,63h,61h,5Eh,5Ch
DB 5Ah,58h,56h,53h,51h,4Fh,4Dh,4Bh,48h,46h,44h,42h,40h,3Eh,3Ch,3Ah
DB 38h,36h,34h,32h,30h,2Eh,2Ch,2Ah,28h,26h,24h,23h,21h,1Fh,1Eh,1Ch
DB 1Ah,19h,17h,16h,14h,13h,12h,10h,0Fh,0Eh,0Dh,0Ch,0Bh,0Ah,09h,08h
DB 07h,06h,05h,05h,04h,03h,03h,02h,02h,01h,01h,01h,00h,00h,00h,00h
DB 00h,00h,00h,00h,00h,01h,01h,01h,02h,02h,03h,03h,04h,05h,05h,06h
DB 07h,08h,09h,0Ah,0Bh,0Ch,0Dh,0Eh,0Fh,10h,12h,13h,14h,16h,17h,19h
DB 1Ah,1Ch,1Eh,1Fh,21h,23h,24h,26h,28h,2Ah,2Ch,2Eh,30h,32h,34h,36h
DB 38h,3Ah,3Ch,3Eh,40h,42h,44h,46h,48h,4Bh,4Dh,4Fh,51h,53h,56h,58h
DB 5Ah,5Ch,5Eh,61h,63h,65h,67h,69h,6Ch,6Eh,70h,72h,74h,76h,78h,7Ah
DB 7Ch,7Eh,80h,82h,84h,86h,88h,8Ah,8Ch,8Eh,90h,91h,93h,95h,96h,98h
DB 9Ah,9Bh,9Dh,9Eh,0A0h,0A1h,0A2h,0A4h,0A5h,0A6h,0A7h,0A8h,0A9h,0AAh,0ABh,0ACh
DB 0ADh,0AEh,0AFh,0AFh,0B0h,0B1h,0B1h,0B2h,0B2h,0B3h,0B3h,0B3h,0B4h,0B4h,0B4h
CosTabE LABEL BYTE


Basic:
0 DEF SEG = &H7000: c = 0
1 pi = 3.14159265#
2 FOR x = 0 TO 2 * pi STEP 2 * pi / 256
3 d = COS(x) * 127 + 127
4 POKE c, d: c = c + 1: NEXT

Most i learned from a book called “Art of Graphics”
(This is image of the book from the internet, i don’t think I still got my copy somewhere.

Raspberry – Arduino Collection

Display case almost done.

Raspberry 1-3 different versions RP400, compute module, zero’s, pico, RP2040 (trinkey). (2012-2023)

I’ve got to many arduino clones, so only atmeta328p, uno, mega, nano ..
And a esp32 esp8066 plus a wemos mini (i use these a lot)

The Arduino’s will have to make place for other Raspberry stuff at a later time.

Custom made case with acrylic protection cover.

These all work, so this is also my stock.
When needed for a project, I will have some spares.

Raspberry Pi History Case

I started a little case for a collection of Raspberry devices.

Over the years, many Raspberries were designed and made.
It all started in 2012
I want to have a case with all RP’s i’ve used.

There are many iterations of the RPi, I’m missing a lot now. If you want to help me, send me old/broken raspberries to get the collection complete!

This is the case at the moment

Case with some Raspberries and Arduino’s I found lying around, I’m not going to dismantle projects. Only the RPi 1A, 4B, Zero, Zero W, Pico and RPi 400 are displayed.
Plastic sheet as protective layer still on there, should be clear as glass.

The case isn’t glued together yet. I’m not sure how and what to include.

  • Horizontal wooden bars to place the devices on?
  • Include a history of Arduino’s for now?
  • Put little notes in the case with information? Like my SDK-85 case?
  • ?

Get information about your RPi version

curl -L https://perturb.org/rpi?rev=$(awk '/^Revision/ { print $3 }' /proc/cpuinfo)

I’ve got a Raspberry 5, lets start experimenting

So many things to try .. and probably buy.
I’m lucky to have this already, official it’s not even out yet.

Specification

  • Processor : Broadcom BCM2712 2.4GHz quad-core 64-bit Arm Cortex-A76 CPU, B with cryptography extensions, 512KB per-core L2 caches, and a 2MB shared L3 cache

Features:

  • VideoCore VII GPU, supporting OpenGL ES 3.1, Vulkan 1.2
  • Dual 4Kp60 HDMI® display output with HDR support
  • 4Kp60 HEVC decoder
  • LPDDR4X-4267 SDRAM
    (4GB and 8GB SKUs available at launch)
  • Dual-band 802.11ac Wi-Fi
  • Bluetooth 5.0 / Bluetooth Low Energy (BLE)
  • microSD card slot, with support for high-speed SDR104 mode
  • 2 × USB 3.0 ports, supporting simultaneous 5Gbps operation
  • 2 × USB 2.0 ports
  • Gigabit Ethernet, with PoE+ support
    (requires separate PoE+ HAT)
  • 2 × 4-lane MIPI camera/display transceivers
  • PCIe 2.0 x1 interface for fast peripherals
    (requires separate M.2 HAT or other adapter)
  • 5V/5A DC power via USB-C, with Power Delivery support
  • Raspberry Pi standard 40-pin header
  • Real-time clock (RTC), powered from external battery
  • Power button

Some things come to mind to test:

  • Kubernetes
  • Dual Camera OpenCV – depthmap and more

You really want to use a case with an active blower to cool the rpi.

Measurements without cooling:

  • Power off – part most hot 28 degrees
  • Power on – Idle, around 40 degrees
  • Power on – Playing 4k for 5 minutes – 60+ degrees

Flir info https://www.henriaanstoot.nl/2023/06/05/checking-faulty-chips-hardware/

I didn’t have a image for Raspberry OS 5 at first, so I took a rpi 4 version and first replaced files in /boot
(Device Tree blob files)

Now at least i could boot into an OS.

Later I got a link to the Alpha boot images, this greatly improved usability and speed 🙂

Youtube 4k movie on a 2560×1080 monitor

Made a little overview website:

https://media.henriaanstoot.nl/websites/rpi5/index.html

Playing with lasercutter steppermotors

Busy day: I’ve airbrushed some 3D pieces a few days ago, but i need 50 or so more.
Meanwhile is was reinstalling octoprint, and making a new version of my Bluetooth page flipper. (Android Music Sheet Pedal Thingy. Which i also didn’t post apparently)
But the main project was this:

I was curious how fast the stepper motors are on my laser cutter. And for what can we utilize this!

So I took a Raspberry Zero and some rotary encoders, lets make an etch-a-sketch like thingy.


Some rotary encoder modules I had.

Next to do: 3D print a pen holder, and alter the code to enable the laser when moving!

CODE

Below code uses a simple rotary class, and generates control GCodes for the steppers/Sculpfun

import time
import serial
import RPi.GPIO as GPIO
from encoder import Encoder

def valueChanged(value, direction):
    print("* New value: {}, Direction: {}".format(value, direction))

GPIO.setmode(GPIO.BCM)

e1 = Encoder(20, 21, valueChanged)
e2 = Encoder(16, 12, valueChanged)

x = 0
y = 0
arduino = serial.Serial('/dev/ttyUSB0', 115200, timeout=.1)

newx = 0
mystringx = ""
newy = 0
mystringy = ""

arduino.write(str.encode("G00 G17 G40 G21 G54\r\n"))
arduino.write(str.encode('G90\r\n'))
arduino.write(str.encode('M4\r\n'))
arduino.write(str.encode('M8\r\n'))
arduino.write(str.encode('G0 X41.5Y36.05\r\n'))
arduino.write(str.encode('M3\r\n'))
#arduino.write(str.encode('G91\r\n'))
arduino.write(str.encode('G1 X2.5F6000S0\r\n'))
arduino.write(str.encode('G1 X0\r\n'))
arduino.write(str.encode('G1 Y0\r\n'))

try:
    while True:
        data = arduino.readline()[:-2] #the last bit gets rid of the new-line chars
        if data:
                print (data)
        arduino.write(str.encode("G1 F10000\r\n"))
        newx=e1.getValue() *5 + 100
        newy=e2.getValue() *5 + 100
        mystringx=f"G1 X{newx}\r\n"
        mystringy=f"G1 Y{newy}\r\n"
#        print(mystringx)
        arduino.write(str.encode(mystringx))
        arduino.write(str.encode(mystringy))

except Exception:
    pass

GPIO.cleanup()

Mobile Raspberry Access Point with Mqtt and a display

UPDATE: 20230214 / 20230224

Install Bullseye on a SDCard

Enable wifi country code using raspi-conf
(While you at it, enable I2C for the display)

Install and configure an Access Point

# As root
apt update
apt upgrade
apt install hostapd
apt install dnsmasq
systemctl stop hostapd
systemctl stop dnsmasq

cat <<EOF > /etc/hostapd/hostapd.conf
interface=wlan0
driver=nl80211
ssid=escape
hw_mode=g
channel=6
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=mysecretpass
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
EOF

cat <<EOF >> /etc/dnsmasq.conf
interface=wlan0
bind-dynamic
domain-needed
bogus-priv
dhcp-range=192.168.50.150,192.168.50.200,255.255.255.0,12h
EOF

cat <<EOF >> /etc/dhcpcd.conf
interface wlan0
nohook wpa_supplicant
static ip_address=192.168.50.10/24
static routers=192.168.50.1
static domain_name_servers=8.8.8.8
EOF

sed -i s/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/g /etc/sysctl.conf


mkdir /etc/nftables
cat <<EOF > /etc/nftables/nft-stat-ap.nft
flush ruleset

table inet ap {
        chain routethrough {
                type nat hook postrouting priority filter; policy accept;
                oifname "eth0" masquerade
        }

        chain fward {
                type filter hook forward priority filter; policy accept;
                iifname "eth0" oifname "wlan0" ct state established,related accept
                iifname "wlan0" oifname "eth0" accept
        }
}
EOF

chmod +x /etc/nftables/nft-stat-ap.nft
cat /etc/nftables.conf | grep nft-stat-ap.nft || echo 'include "/etc/nftables/nft-stat-ap.nft"' >> /etc/nftables.conf

systemctl unmask hostapd
systemctl enable hostapd
systemctl enable nftables

reboot

UPDATE: 20230214

Now in its case, added two buttons and one led.

UPDATE : 20230224 mqtt config

apt-get install mosquitto mosquitto-clients

vi /etc/mosquitto/conf.d/remotemqtt.conf
per_listener_settings true
# internal mqtt
listener 1883
allow_anonymous true
# connection over the internet
connection bridge-01
address remoteserver:8883
bridge_cafile /etc/mosquitto/certs/ca.crt
bridge_keyfile /etc/mosquitto/certs/remoteaccesspoint.key
bridge_certfile /etc/mosquitto/certs/remoteaccesspoint.crt
topic escape/# both 0
remote_username remoteuser
remote_password remotepass

########## remote server config

cd /etc/mosquitto
mosquitto_passwd passwords remoteuser

cd /etc/mosquitto/certs
./generate-CA.sh client remoteaccesspoint

copy ca.crt remoteaccesspoint.key and remoteaccesspoint.crt to accesspoint

mosquitto.conf
pid_file /var/run/mosquitto.pid
persistence true
persistence_location /var/lib/mosquitto/
#per_listener_settings true
# Plain MQTT protocol
listener 1883
allow_anonymous true
# End of plain MQTT configuration
# MQTT over TLS/SSL
listener 8883
cafile /etc/mosquitto/certs/ca.crt
certfile /etc/mosquitto/certs/webserver.fash.lab.crt
keyfile /etc/mosquitto/certs/webserver.fash.lab.key
allow_anonymous false
password_file /etc/mosquitto/passwords
# End of MQTT over TLS/SLL configuration
listener 9001
protocol websockets
# End of plain Websockets configuration
# WebSockets over TLS/SSL
listener 9883
protocol websockets
cafile /etc/mosquitto/certs/ca.crt
certfile /etc/mosquitto/certs/webserver.fash.lab.crt
keyfile /etc/mosquitto/certs/webserver.fash.lab.key
log_dest file /var/log/mosquitto/mosquitto.log
include_dir /etc/mosquitto/conf.d
connection bridge-01
address extramqttserver:1883
topic lscspm1/# both 0
topic owntracks/# both 0
topic escape/# both 0

log_type all


Controlling Display and MQTT messages examples

apt-get install python3-smbus

python3 printline.py -1 "line 1" -2 "line 2"

wget https://github.com/emcniece/rpi-lcd/blob/master/RPi_I2C_driver.py

cat printline.py
# requires RPi_I2C_driver.py
import RPi_I2C_driver
from time import *
import sys, getopt

#python3 fix
unichr = chr 

mylcd = RPi_I2C_driver.lcd()
# test 2                  1234567812345678


def main(argv):
   line1 = ''
   line2 = ''
   try:
      opts, args = getopt.getopt(argv,"h1:2:",["txt1=","txt2="])
   except getopt.GetoptError:
      print ('printline.py -1 <line1> -2 <line2>')
      sys.exit(2)
   for opt, arg in opts:
      if opt == '-h':
         print ('printline.py -1 <line1> -2 <line2>')
         sys.exit()
      elif opt in ("-1", "--txt1"):
         line1 = arg
      elif opt in ("-2", "--txt2"):
         line2 = arg

   mylcd.lcd_display_string(line1, 1)
   mylcd.lcd_display_string(line2, 2)
if __name__ == "__main__":
   main(sys.argv[1:])

Print internal and external ip

myip=$(/usr/sbin/ifconfig eth0 | grep "inet " | awk '{ print $2 }')
extip=$(curl -s http://whatismyip.akamai.com/)
python3 printline.py -1 "i $myip" -2 "e $extip"

mosquitto health tester

timeout 1 mosquitto_sub -t '$SYS/#' -C 1 | grep -v Error || exit 1

Button press shutdown

raspi-gpio get 27  | grep level=0 >/dev/null 
if [ $? == 0 ] ; then

python3 printline.py -1 "shutting" -2 "down"
/usr/sbin/halt -p
fi

Cleaned-up minimal mqtt poster

#include <WiFi.h>
#include <PubSubClient.h>

const char* ssid = "ssidname";
const char* password = "ssidpass";
const char* mqttServer = "192.168.50.10";

WiFiClient espClient;
PubSubClient client(espClient);


void initWiFi() {
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  Serial.print("Connecting to WiFi ..");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print('.');
    delay(1000);
  }
  Serial.println(WiFi.localIP());
}


void setup() {
Serial.begin(115200);
initWiFi();
  Serial.print("RRSI: ");
  Serial.println(WiFi.RSSI());
    client.setClient(espClient);
    client.setServer(mqttServer,1883);
 if (client.connect("testmodule")) {

      Serial.println("connected");
 client.publish("escape/testclient", "connected");
    } else {
            Serial.println("Mqtt not connected");
    }

}

void loop() {
        }

}