Posts

Showing posts from July, 2024

Pi pico and DS18b20 temperature sensor

Image
Pi Pico and one wire DS18b20 temperature sensor works Temperature readings from Pi Pico using 1 wire DS18b20 using code from site below and their code. # Complete project details at https://RandomNerdTutorials.com/raspberry-pi-pico-ds18b20-micropython/ import machine , onewire , ds18x20 , time ds_pin = machine . Pin ( 22 ) ds_sensor = ds18x20 . DS18X20 ( onewire . OneWire ( ds_pin ) ) roms = ds_sensor . scan ( ) print ( 'Found DS devices: ' , roms ) while True : ds_sensor . convert_temp ( ) time . sleep_ms ( 750 ) for rom in roms : print ( rom ) tempC = ds_sensor . read_temp ( rom ) tempF = tempC * ( 9 / 5 ) + 32 print ( 'temperature (ºC):' , "{:.2f}" . format ( tempC ) ) print ( 'temperature (ºF):' , "{:.2f}" . format ( tempF ) ) print ( ) time . sleep ( 5 )

pi pico OLED, SD card combined (Version 2)

Image
NB pi pico pinout at the bottom. Fri Sep 20 11:25:39 NZST 2024 changed one of the lines and ran  digikey4pluSD1P.py again. Worked. Now going to put this program into pi pico with wifi (ie picoW) and replace previous pico.  Wrote code for SD card and for OLED and put them into one program here in Pastebin Here's the Thonny micropython  Code: (OLED stuff from Tom's Hardware (The SD card code and wire-up came from Digikey    #Combined digikey4 with Tom0Oled to get CD card reader and OLED display in one program. Worked 4:28,30/07/24 #first, do imports for SD card print("Simple SD card testDigiKey1.1 ")  #Tue Jun 28 17:09:24 NZST 2022  print("Pi Pico and Code with Thonny.") import machine import sdcard  import os  #why not uos? #Next lines are for CD card. Originally from digikey4 from machine import Pin, I2C #12:04, 30/07/24 Worked from ssd1306 import SSD1306_I2C i2c=I2C(0,sda=Pin(0), scl=Pin(1), freq=400000) oled = SSD1306_I2C(128, 64, i2c) ole...

Pi pico SD card

Image
 This worked from code and wire-up from 2 years ago. Surprised. Pleased. Used this code: <script src="https://pastebin.com/embed_js/W0CWw2rx"></script> <--pastebi https://www.digikey.co.nz/en/maker/projects/raspberry-pi-pico-rp2040-sd-card-example-with-micropython-and-cc/e472c7f578734bfd96d437e68e670050 From #Amazing. This worked 2 yeas later print("Simple SD card testDigiKey1.1 ")  #Tue Jun 28 17:09:24 NZST 2022 print("Pi Pico and Code with Thonny.") import machine import sdcard  import os  #why not uos? # Assign chip select (CS) pin (and start it high) cs = machine.Pin(9, machine.Pin.OUT)  #does this really start high? # Intialize SPI peripheral (start with 1 MHz) Check it IS 1000000 spi = machine.SPI(1,                   baudrate=100000,                   polarity=0,                   phase=0,     ...

Triangle centres

Image
 I wanted to depict the centroid, incentre and orthocentre of an arbitrary triangle using python311 and matplotlib. The goal was to make the image seen in the Wikipedia image below. https://en.wikipedia.org/wiki/File:Triangle_centers2.svg So, here was the starting version below. Just a start. Code to do this consists of 4 files. One each for the three centres and a third one dotri3.py that does the actual matplotlib drawing. A lot was learned, especially about Python, editors including IDLE and Thonny and arrangements of functions with imports. The programs are: dotri3.py  <script src="https://pastebin.com/embed_js/cqjsdxcb"></script> cntroid7.py  <script src="https://pastebin.com/embed_js/C14Ns3aS"></script> incentre7.py  <script src="https://pastebin.com/embed_js/wnjirfCE"></script> ortho6.py  <script src="https://pastebin.com/embed_js/XvekbJPf"></script> Further  Further work on this project incl...