tag:blogger.com,1999:blog-24621299502620777292024-03-14T05:33:45.228-07:00Hello Raspberry Pi<i>Please visit my new address:</i> <b><a href="https://coxxect.blogspot.com/">https://coxxect.blogspot.com/</a></b>Erikhttp://www.blogger.com/profile/04983894331825656853noreply@blogger.comBlogger720125tag:blogger.com,1999:blog-2462129950262077729.post-53515100646691288402022-08-08T21:01:00.003-07:002022-08-08T21:01:19.920-07:00SSD1306 SPI OLED on Raspberry Pi Pico/CircuitPython<p>
Raspberry Pi Pico (RP2040) running CircuitPython 7.3.2, to drive 0.96" 128x64
SSD1306 SPI OLED using displayio. Check
<b
><a
href="https://coxxect.blogspot.com/2022/08/ssd1306-spi-oled-on-raspberry-pi.html"
>here</a
></b
>.
</p>
<br/>
<center>
<iframe width="560" height="315" src="https://www.youtube.com/embed/YobGFYb7Shc" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</center>Erikhttp://www.blogger.com/profile/04983894331825656853noreply@blogger.com0tag:blogger.com,1999:blog-2462129950262077729.post-28779771667826263922022-07-16T10:03:00.004-07:002022-07-16T10:10:58.738-07:00Fixed: Raspberry Pi OS cannot find 5G Hz WiFi Network<p>
Recently, when I tried 64 bit Raspberry Pi OS (Bullseye) on Raspberry Pi
4B/4G, it's found 5G Hz WiFi Networks cannot be discovered, and connected.<br /><br />To
fix it, I set set WiFi Country to US.<br />
</p>
<center>
<iframe allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/5-uToi9BRBE" title="YouTube video player" width="560"></iframe>
</center>
<br />
<p>
MENU > Preferences > Raspberry Pi Configuration<br />> select
Localisation tab<br />> Set WiFi Country...<br />> Select US United
States<br />
</p>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpa1dMgsDwFje3EY_ja5duK_A94TNElaTPzC5l0LoNGYpkz4lHQJK8mvQbLXZGi0jWu8pSh4q42AYd3-lPgHPoZmKifQY1FBvWOUkA5aXd_H2eib9m0Eg4tnXy_ycJtLengp_lDj4UlDnMHy8-mDlQENRCZk85L9A1uySPCr3-Bab1sykgtA0FE72q/s1280/wifi%20config%205G.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="1280" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpa1dMgsDwFje3EY_ja5duK_A94TNElaTPzC5l0LoNGYpkz4lHQJK8mvQbLXZGi0jWu8pSh4q42AYd3-lPgHPoZmKifQY1FBvWOUkA5aXd_H2eib9m0Eg4tnXy_ycJtLengp_lDj4UlDnMHy8-mDlQENRCZk85L9A1uySPCr3-Bab1sykgtA0FE72q/w640-h360/wifi%20config%205G.png" width="640" /></a>
</div>
<br />
<div>
remark:<br />I have another Raspberry Pi 4B/8G running 32 bit Raspberry Pi OS
(Buster), no this problem.
</div>
<div><br /><br /></div>
Erikhttp://www.blogger.com/profile/04983894331825656853noreply@blogger.com0tag:blogger.com,1999:blog-2462129950262077729.post-7333456538179059032022-07-15T10:28:00.003-07:002022-07-15T10:41:24.072-07:00Install and run 64-bit Ubuntu MATE 22.04 LTS on Raspberry Pi 4<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEineqAziVYmHyqgsnlHUPCOi3zRqgMT7LbZrQeh5UWlo4r8zcoTDtJbmo88sjv3RlcOcxUmglrudgfaKNaczFTiQSs9SdIcGqp9WCUHxUEPHKn4LAGlo5SpQAh64VShn1O3mazSw2W3CnasFxyyR1C02UZn_hw88IndyyiLOklyrb9HdQCKU4QuLUhk/s1280/Ubuntu%20MATE%2022.04%20LTS%20on%20Raspberry%20Pi%204.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="1280" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEineqAziVYmHyqgsnlHUPCOi3zRqgMT7LbZrQeh5UWlo4r8zcoTDtJbmo88sjv3RlcOcxUmglrudgfaKNaczFTiQSs9SdIcGqp9WCUHxUEPHKn4LAGlo5SpQAh64VShn1O3mazSw2W3CnasFxyyR1C02UZn_hw88IndyyiLOklyrb9HdQCKU4QuLUhk/w640-h360/Ubuntu%20MATE%2022.04%20LTS%20on%20Raspberry%20Pi%204.png" width="640" /></a>
</div>
<br />
<p></p>
<p>
<b><a href="http://ubuntu-mate.org" target="_blank">ubuntu-mate.org</a></b>
provide ready-to-run images for the Raspberry Pi SBC.<br /><br />Here show
steps to prepare on Raspberry Pi 0S 64-bit (bullseye), install 64-bit Ubuntu
MATE 22.04 LTS on Raspberry Pi 4B/4G Rev 1.2 on
<a href="https://helloraspberrypi.blogspot.com/2022/07/raspberry-pi-run-on-ssd-via-usb-8.html">Kingston A400 SSD 120GB SATA (using Orico HDD Adapter Kit USB3.0
adapter)</a>. For sure, you can install on Micro SD.<br />
</p>
<center>
<iframe allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/KKMGSCz7O_4" title="YouTube video player" width="560"></iframe>
</center>
<br />
To enable Boot from USB for Raspberry Pi 4, read <a href="https://helloraspberrypi.blogspot.com/2022/07/enable-boot-from-usb-for-raspberry-pi.html">HERE</a>.<br /><br /><br />Erikhttp://www.blogger.com/profile/04983894331825656853noreply@blogger.com0tag:blogger.com,1999:blog-2462129950262077729.post-62750367001213663132022-07-14T01:13:00.003-07:002022-07-15T10:43:51.702-07:00Enable Boot from USB for Raspberry Pi 4/400<p>
Raspberry Pi 4, 400 and Compute Module 4 computers use an EEPROM to boot the
system. If you want to boot your Raspberry Pi 4/400, the bootloader have to be
updated.<br />
</p><center>
<iframe allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/qnl2ZLhQ1NM" title="YouTube video player" width="560"></iframe>
</center>
<br />Steps in my practice:<br /><br /><u>Update system using apt</u><br /><br /><b>$ sudo apt update<br />$ sudo apt full-upgrade</b><br /><br /><u>Run raspi-config in command line</u> (not GUI version)<br /><br /><b>$ sudo raspi-config<br />> Select Advanced Options<br />> Select
Bootloader Version<br />> Select Latest for the latest stable bootloader
release.<br />> Reboot</b><br /><br />reference: <a href="https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#raspberry-pi-4-boot-eeprom" target="_blank">https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#raspberry-pi-4-boot-eeprom</a><br /><br /><b><u><i>rematk:</i></u></b><br /><br />In my own case, I have two Raspberry Pi 4, tried to
<a href="https://helloraspberrypi.blogspot.com/2022/07/raspberry-pi-run-on-ssd-via-usb-8.html">run Raspberry Pi OS 64 bit bullseys from Kingston A400 SSD 120GB SATA
attached with Orico HDD Adapter Kit USB3.0</a>.<br /><br />case 1 - Raspberry Pi 4B/4G running 64 bit Raspberry Pi OS 11
(bullseye): no need doing anything, it boot from USB SSD automatically after
reboot with original Micro SD removed.<br /><br />case 2 - Raspberry Pi
4B/8G running 32 bit Raspberry Pi OS 10 (Buster): apt update/full-upgrade, and
reboot cannot solve. Have to run raspi-config to select Bootloader Version
(Latest I selected).
<p></p>
<p><br /></p>
<hr />
<p>May be you will interested:<br />~ <a href="https://helloraspberrypi.blogspot.com/2022/07/install-and-run-64-bit-ubuntu-mate-2204.html">Install and run 64-bit Ubuntu MATE 22.04 LTS on Raspberry Pi 4</a><br /><br /><br /></p>
Erikhttp://www.blogger.com/profile/04983894331825656853noreply@blogger.com0tag:blogger.com,1999:blog-2462129950262077729.post-10282426378671578062022-07-13T04:15:00.005-07:002022-07-14T01:14:29.400-07:00Raspberry Pi run on ssd via USB<p>
Just install Raspberry Pi 0S 64-bit (bullseye), run o Raspberry Pi 4B/4G Rev
1.2.<br />
</p>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPslxmUgscLih02c5KBv048Or-pqgqkKC1VKs_Djz9S0kIT0dMDPnnGOWJbJaHageKbZpc33PUCz7_xWsWiASlG7wYBOmiftPCQiGmuNKWo89Lh-LvOw7_YIV99EZzQCu8PeQMybOrAGqYnm13PMEp37-1056e9lN873YkAQiHnv9fIwDZwDB9mJhs/s1000/Raspberry%20Run%20on%20SSD.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="750" data-original-width="1000" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPslxmUgscLih02c5KBv048Or-pqgqkKC1VKs_Djz9S0kIT0dMDPnnGOWJbJaHageKbZpc33PUCz7_xWsWiASlG7wYBOmiftPCQiGmuNKWo89Lh-LvOw7_YIV99EZzQCu8PeQMybOrAGqYnm13PMEp37-1056e9lN873YkAQiHnv9fIwDZwDB9mJhs/s320/Raspberry%20Run%20on%20SSD.jpg" width="320" /></a>
</div>
<div>
<p><br /></p>
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIPau37Kf81zuQIcPjfpCgQ7P_T3t0PRnc4cdpfO_oz2dgku6KwE3i2L5aztiJFVmL4i0S2ZhcjW59GEufab14LVWG-203Dk7OllcRTXbB9hxXIuKKzwkvgnphgo-AZZw-wvWxHM-GMOwZtE4lza2v8xq5hGOrCwrtNLQz2jIk3nh6x7XvOdCSoWpK/s1280/Raspberry%20Run%20on%20SSD_02.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="1280" height="180" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIPau37Kf81zuQIcPjfpCgQ7P_T3t0PRnc4cdpfO_oz2dgku6KwE3i2L5aztiJFVmL4i0S2ZhcjW59GEufab14LVWG-203Dk7OllcRTXbB9hxXIuKKzwkvgnphgo-AZZw-wvWxHM-GMOwZtE4lza2v8xq5hGOrCwrtNLQz2jIk3nh6x7XvOdCSoWpK/s320/Raspberry%20Run%20on%20SSD_02.png" width="320" /></a>
</div>
<div><br />Tested with Raspberry Pi Diagnostic SD Card Speed Test.</div>
<div><br /></div>
<div>- The ssd used is Kingston A400 SSD 120GB SATA.</div>
<div>- The adapter is Orico HDD Adapter Kit USB3.0.<br /><br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj99wI_xDFseyUBvUkfHelsU_Me2chs9PJjdvQS-qvUcWf3WQdNA7itNR4JvQzIJ2HN9UoZ2bzp2tozg1YXwE2bOiw5zyzJDk6x2AvjsMNjaWUjuuG1ntQF-7bZIhDmxk_b1iq32iDi62_RQRIctDWsl85I70htORJHEa0fW4HZTOVC56bXc5xV33of/s1280/SD%20Card%20Speed%20Test_SSD_01.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="1280" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj99wI_xDFseyUBvUkfHelsU_Me2chs9PJjdvQS-qvUcWf3WQdNA7itNR4JvQzIJ2HN9UoZ2bzp2tozg1YXwE2bOiw5zyzJDk6x2AvjsMNjaWUjuuG1ntQF-7bZIhDmxk_b1iq32iDi62_RQRIctDWsl85I70htORJHEa0fW4HZTOVC56bXc5xV33of/w640-h360/SD%20Card%20Speed%20Test_SSD_01.png" width="640" /></a>
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjd8XWMU_igNqw-J80RZlMw7tfajvWMm9KouGdvdGU8L-qGb4FpBbi7DEPCjTaTPOg_-ruxiap7xVuYGd4bmiH2dnqU1MGMXnUVk3aGSUwp6r5geHgRnfQ16R0rTwTgtmIZpMgK3h1W-QlBNBpC_nVPrT9MC2TzQqAkt6LsYCapy-BE85QDE7n8gOWk/s1280/SD%20Card%20Speed%20Test_SSD_02.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="1280" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjd8XWMU_igNqw-J80RZlMw7tfajvWMm9KouGdvdGU8L-qGb4FpBbi7DEPCjTaTPOg_-ruxiap7xVuYGd4bmiH2dnqU1MGMXnUVk3aGSUwp6r5geHgRnfQ16R0rTwTgtmIZpMgK3h1W-QlBNBpC_nVPrT9MC2TzQqAkt6LsYCapy-BE85QDE7n8gOWk/w640-h360/SD%20Card%20Speed%20Test_SSD_02.png" width="640" /></a>
</div>
<br /><br />
Log, rpdiags.txt.
<pre style="border: 1px solid black;"><code><span style="color: black;">Raspberry Pi Diagnostics - version 0.10
Wed Jul 13 14:40:42 2022
Test : SD Card Speed Test
Run 1
prepare-file;0;0;213472;416
seq-write;0;0;174762;341
rand-4k-write;0;0;22351;5587
rand-4k-read;16478;4119;0;0
Sequential write speed 174762 KB/sec (target 10000) - PASS
Random write speed 5587 IOPS (target 500) - PASS
Random read speed 4119 IOPS (target 1500) - PASS
Test PASS
</span></code></pre>
<br />
Compare with the original MicroSD I used, Samsung EVO Plus 128G<br /><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFfqQyhST3MdkfgZ9JPI8qbBib4UNG7gKyInLUrt5RKjqbKKHTjti_JBnzd0nihKrVBh15feLCM3gN0cv8nulmYno4Wm2MYHt41MEIItEln0cou3XikQS9KMTcFGrxknlSXXqNW0Hkpk7_IKkl5M3u62WdplHo1YBiKU18UGUHqOPaBse2Hxrl_e9y/s1280/SD%20Card%20Speed%20Test_Samsung_EVO_plus.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="1280" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFfqQyhST3MdkfgZ9JPI8qbBib4UNG7gKyInLUrt5RKjqbKKHTjti_JBnzd0nihKrVBh15feLCM3gN0cv8nulmYno4Wm2MYHt41MEIItEln0cou3XikQS9KMTcFGrxknlSXXqNW0Hkpk7_IKkl5M3u62WdplHo1YBiKU18UGUHqOPaBse2Hxrl_e9y/w640-h360/SD%20Card%20Speed%20Test_Samsung_EVO_plus.png" width="640" /></a>
</div>
<br />
<pre style="border: 1px solid black;"><code><span style="color: black;">Raspberry Pi Diagnostics - version 0.10
Wed Jul 13 17:33:10 2022
Test : SD Card Speed Test
Run 1
prepare-file;0;0;13742;26
seq-write;0;0;32621;63
rand-4k-write;0;0;3040;760
rand-4k-read;13407;3351;0;0
Sequential write speed 32621 KB/sec (target 10000) - PASS
Random write speed 760 IOPS (target 500) - PASS
Random read speed 3351 IOPS (target 1500) - PASS
Test PASS
</span></code></pre>
<br /><br />
<hr /><b><u>
Update firmware to enable Boot from USB</u></b><br /><br />Make sure to update latest firmware and enable Boot from USB, read <a href="https://helloraspberrypi.blogspot.com/2022/07/enable-boot-from-usb-for-raspberry-pi.html">Enable Boot from USB for Raspberry Pi 4/400</a>.<div><br /><br /></div><div><br />
<br />
</div>Erikhttp://www.blogger.com/profile/04983894331825656853noreply@blogger.com0tag:blogger.com,1999:blog-2462129950262077729.post-22776172966594824472022-05-10T15:17:00.001-07:002022-05-10T15:30:30.906-07:00CircuitPython display cursor on displayio, work on Raspberry Pi Pico/ST7789 SPI Display.<p>
CircuitPython exercise run on Raspberry Pi Pico + 240x240 ST7789 SPI RGB
Display, to display cursor on displayio.<br />
</p>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnhYaD7JCf-ZUoOvZ1qJQ9Hf0OO99WzgSqxKrLyYiVGurPZmjoKXaBdtrOHVBmyiEGJQrafgX3S8WRVA2NgMCv5vUL5Val9I0zT5XrQJWkyYYU9XxiLKd96le9rrUxIAK1EiZVBiRC4NsTJUiPF56RTNIUok-wlx0gx9hK-vpcv428jCXhF7N96jtA/s1000/circuitpython_cursor.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="606" data-original-width="1000" height="388" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnhYaD7JCf-ZUoOvZ1qJQ9Hf0OO99WzgSqxKrLyYiVGurPZmjoKXaBdtrOHVBmyiEGJQrafgX3S8WRVA2NgMCv5vUL5Val9I0zT5XrQJWkyYYU9XxiLKd96le9rrUxIAK1EiZVBiRC4NsTJUiPF56RTNIUok-wlx0gx9hK-vpcv428jCXhF7N96jtA/w640-h388/circuitpython_cursor.jpg" width="640" /></a>
</div>
<br />
<div>
Libraries needed:<br />- adafruit_cursorcontrol folder<br />-
adafruit_display_text folder<br />- adafruit_st7789.mpy<br /><br />
<center>
<iframe allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/rnaCfNSQPC8" title="YouTube video player" width="560"></iframe>
</center>
<br /><b><u>Code:</u><br /><br />cpyPico_st7789_240_cursor_mapping.py</b>
</div>
<div>
<div>
cursor position are mapped to variable resistor position.<br /><br />
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhg03RQj79BgEScx_2L1Dd8G4bUr6dvYImNM0-CtTqWyzNI2BRL6PmI8KADm1QhNBwm6WwoqiiBoYaa5VCmfMNRCr8oLB9vqtKnUXqEMgil9DPxb09bHnibHF_iPuJjA7w3xnakPLzXwdE7vgN3sw1FHs-HsBDoKXFlJuBRXdALUz5fDrD7vrsiNubT/s1000/cpyPico_st7789_240_cursor_mapping.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="754" data-original-width="1000" height="241" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhg03RQj79BgEScx_2L1Dd8G4bUr6dvYImNM0-CtTqWyzNI2BRL6PmI8KADm1QhNBwm6WwoqiiBoYaa5VCmfMNRCr8oLB9vqtKnUXqEMgil9DPxb09bHnibHF_iPuJjA7w3xnakPLzXwdE7vgN3sw1FHs-HsBDoKXFlJuBRXdALUz5fDrD7vrsiNubT/s320/cpyPico_st7789_240_cursor_mapping.jpg" width="320" /></a>
</div>
</div>
<pre style="border: 1px solid black;"><code><span style="color: black;">"""
Example of CircuitPython/RaspberryPi Pico
+ 240x240 ST7789 SPI RGB screen.
display cursor on displayio.
cursor position are mapped to variable resistor position
using adafruit_cursorcontrol.cursorcontrol
https://docs.circuitpython.org/projects/cursorcontrol/en/latest/api.html
</span><span style="color: red;">Connection between Pico and
the IPS screen, with ST7789 SPI interface.
3V3 - BLK (backlight, always on)
GP11 - CS
GP12 - DC
GP13 - RES
GP15 - SDA
GP14 - SCL
3V3 - VCC
GND - GND
AnalogIn GP26_A0 connect to variable resistor for Y
AnalogIn GP26_A1 connect to variable resistor for X</span><span style="color: black;">
"""
import os
import sys
import board
import time
import terminalio
import displayio
import busio
from adafruit_display_text import label
import adafruit_st7789
import adafruit_cursorcontrol.cursorcontrol
from analogio import AnalogIn
print("=====================================")
info = sys.implementation[0] + ' ' + \
os.uname()[3] + '\n' + \
'run on ' + os.uname()[4]
print(info)
print("=====================================")
print(adafruit_st7789.__name__ + " version: " +
adafruit_st7789.__version__)
print(adafruit_cursorcontrol.cursorcontrol.__name__
+ " version: "
+ adafruit_cursorcontrol.cursorcontrol.__version__)
print()
analog_A0 = AnalogIn(board.GP26_A0)
analog_A1 = AnalogIn(board.GP27_A1)
# Release any resources currently in use for the displays
displayio.release_displays()
tft_cs = board.GP11
tft_dc = board.GP12
tft_res = board.GP13
spi_mosi = board.GP15
spi_clk = board.GP14
display_width = 240
display_height = 240
"""
classbusio.SPI(clock: microcontroller.Pin,
MOSI: Optional[microcontroller.Pin] = None,
MISO: Optional[microcontroller.Pin] = None)
"""
spi = busio.SPI(spi_clk, MOSI=spi_mosi)
display_bus = displayio.FourWire(
spi, command=tft_dc, chip_select=tft_cs, reset=tft_res
)
display = adafruit_st7789.ST7789(display_bus,
width=display_width, height=display_height,
rowstart=80,
rotation=180)
# Make the display context
splash = displayio.Group()
display.show(splash)
color_bitmap = displayio.Bitmap(display_width, display_height, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0xA0A0A0
bg_sprite = displayio.TileGrid(color_bitmap,
pixel_shader=color_palette, x=0, y=0)
splash.append(bg_sprite)
# Draw a smaller inner rectangle
inner_bitmap = displayio.Bitmap(80, 180, 1)
inner_palette = displayio.Palette(1)
inner_palette[0] = 0x0000FF
inner_sprite = displayio.TileGrid(inner_bitmap,
pixel_shader=inner_palette, x=20, y=20)
splash.append(inner_sprite)
info1 = sys.implementation[0] + ' ' + os.uname()[2]
info2 = 'run on ' + os.uname()[4]
# Draw labels for CircuitPython info
text_group1 = displayio.Group(scale=2, x=5, y=40)
text1 = info1
text_area1 = label.Label(terminalio.FONT, text=text1, color=0x000000)
text_group1.append(text_area1) # Subgroup for text scaling
#
text_group2 = displayio.Group(scale=1, x=5, y=70)
text2 = info2
text_area2 = label.Label(terminalio.FONT, text=text2, color=0xFFFFFF)
text_group2.append(text_area2) # Subgroup for text scaling
# Draw labels for adafruit_st7789
text_group3 = displayio.Group(scale=2, x=5, y=120)
text3 = adafruit_st7789.__name__
text_area3 = label.Label(terminalio.FONT, text=text3, color=0x000000)
text_group3.append(text_area3) # Subgroup for text scaling
#
text_group4 = displayio.Group(scale=2, x=5, y=150)
text4 = adafruit_st7789.__version__
text_area4 = label.Label(terminalio.FONT, text=text4, color=0xFF0000)
text_group4.append(text_area4) # Subgroup for text scaling
# Draw labels for adafruit_cursorcontrol.cursorcontrol
text_group5 = displayio.Group(scale=1, x=5, y=180)
text5 = adafruit_cursorcontrol.cursorcontrol.__name__
text_area5 = label.Label(terminalio.FONT, text=text5, color=0x000000)
text_group5.append(text_area5) # Subgroup for text scaling
#
text_group6 = displayio.Group(scale=2, x=5, y=210)
text6 = adafruit_cursorcontrol.cursorcontrol.__version__
text_area6 = label.Label(terminalio.FONT, text=text6, color=0x000000)
text_group6.append(text_area6) # Subgroup for text scaling
splash.append(text_group1)
splash.append(text_group2)
splash.append(text_group3)
splash.append(text_group4)
splash.append(text_group5)
splash.append(text_group6)
</span><span style="color: red;"># initialize the mouse cursor object
# place over all others
mouse_cursor = adafruit_cursorcontrol.cursorcontrol.Cursor(
display, display_group=splash)</span><span style="color: black;">
cnv_ratio = 240/65536
while True:
</span><span style="color: red;">mouse_cursor.x = (int)(analog_A1.value * cnv_ratio)
mouse_cursor.y = (int)((64436-analog_A0.value) * cnv_ratio)</span><span style="color: black;">
time.sleep(0.05)
print("~ bye ~")<span style="font-family: Times New Roman;"><span style="white-space: normal;">
</span></span></span></code></pre>
<div>
<b>cpyPico_st7789_240_cursor_delta.py</b><br />variable resistor position
control the cursor movement.
</div>
<div><br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-zvM7tRIQh-fZc4dAFMVZhWQv0iu3AqPKhRo6On55ozocgvh0NDYl7t0q_7rcLPCF2M4d5OJpCkq48sR79Ve9_yBQFtI6hVD8lJb1Q87JAlL5IYZKG_uUEmvaknEvsDCYYdJhQlJ2ejZzVF0Irfm-qrr0qDKxdhMV2m8VNkxFD7WWAsVeNlzgD4vi/s1000/cpyPico_st7789_240_cursor_delta.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="754" data-original-width="1000" height="241" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-zvM7tRIQh-fZc4dAFMVZhWQv0iu3AqPKhRo6On55ozocgvh0NDYl7t0q_7rcLPCF2M4d5OJpCkq48sR79Ve9_yBQFtI6hVD8lJb1Q87JAlL5IYZKG_uUEmvaknEvsDCYYdJhQlJ2ejZzVF0Irfm-qrr0qDKxdhMV2m8VNkxFD7WWAsVeNlzgD4vi/s320/cpyPico_st7789_240_cursor_delta.jpg" width="320" /></a>
</div>
<br />
<pre style="border: 1px solid black;"><code><span style="color: black;">"""
Example of CircuitPython/RaspberryPi Pico
+ 240x240 ST7789 SPI RGB screen.
display cursor on displayio.
variable resistor position control the cursor movement.
Connection between Pico and
the IPS screen, with ST7789 SPI interface.
3V3 - BLK (backlight, always on)
GP11 - CS
GP12 - DC
GP13 - RES
GP15 - SDA
GP14 - SCL
3V3 - VCC
GND - GND
AnalogIn GP26_A0 connect to variable resistor for Y
AnalogIn GP26_A1 connect to variable resistor for X
"""
import os
import sys
import board
import time
import terminalio
import displayio
import busio
from adafruit_display_text import label
import adafruit_st7789
import adafruit_cursorcontrol.cursorcontrol
from analogio import AnalogIn
print("=====================================")
info = sys.implementation[0] + ' ' + \
os.uname()[3] + '\n' + \
'run on ' + os.uname()[4]
print(info)
print("=====================================")
print(adafruit_st7789.__name__ + " version: " +
adafruit_st7789.__version__)
print(adafruit_cursorcontrol.cursorcontrol.__name__
+ " version: "
+ adafruit_cursorcontrol.cursorcontrol.__version__)
print()
analog_A0 = AnalogIn(board.GP26_A0)
analog_A1 = AnalogIn(board.GP27_A1)
# Release any resources currently in use for the displays
displayio.release_displays()
tft_cs = board.GP11
tft_dc = board.GP12
tft_res = board.GP13
spi_mosi = board.GP15
spi_clk = board.GP14
display_width = 240
display_height = 240
"""
classbusio.SPI(clock: microcontroller.Pin,
MOSI: Optional[microcontroller.Pin] = None,
MISO: Optional[microcontroller.Pin] = None)
"""
spi = busio.SPI(spi_clk, MOSI=spi_mosi)
display_bus = displayio.FourWire(
spi, command=tft_dc, chip_select=tft_cs, reset=tft_res
)
display = adafruit_st7789.ST7789(display_bus,
width=display_width, height=display_height,
rowstart=80,
rotation=180)
# Make the display context
splash = displayio.Group()
display.show(splash)
color_bitmap = displayio.Bitmap(display_width, display_height, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0xA0A0A0
bg_sprite = displayio.TileGrid(color_bitmap,
pixel_shader=color_palette, x=0, y=0)
splash.append(bg_sprite)
# Draw a smaller inner rectangle
inner_bitmap = displayio.Bitmap(50, 180, 1)
inner_palette = displayio.Palette(1)
inner_palette[0] = 0x0000FF
inner_sprite = displayio.TileGrid(inner_bitmap,
pixel_shader=inner_palette, x=50, y=20)
#splash.append(inner_sprite)
info1 = sys.implementation[0] + ' ' + os.uname()[2]
info2 = 'run on ' + os.uname()[4]
# Draw labels for CircuitPython info
text_group1 = displayio.Group(scale=2, x=5, y=40)
text1 = info1
text_area1 = label.Label(terminalio.FONT, text=text1, color=0x000000)
text_group1.append(text_area1) # Subgroup for text scaling
#
text_group2 = displayio.Group(scale=1, x=5, y=70)
text2 = info2
text_area2 = label.Label(terminalio.FONT, text=text2, color=0xFFFFFF)
text_group2.append(text_area2) # Subgroup for text scaling
# Draw labels for adafruit_st7789
text_group3 = displayio.Group(scale=2, x=5, y=120)
text3 = adafruit_st7789.__name__
text_area3 = label.Label(terminalio.FONT, text=text3, color=0x000000)
text_group3.append(text_area3) # Subgroup for text scaling
#
text_group4 = displayio.Group(scale=2, x=5, y=150)
text4 = adafruit_st7789.__version__
text_area4 = label.Label(terminalio.FONT, text=text4, color=0xFF0000)
text_group4.append(text_area4) # Subgroup for text scaling
# Draw labels for adafruit_cursorcontrol.cursorcontrol
text_group5 = displayio.Group(scale=1, x=5, y=180)
text5 = adafruit_cursorcontrol.cursorcontrol.__name__
text_area5 = label.Label(terminalio.FONT, text=text5, color=0x000000)
text_group5.append(text_area5) # Subgroup for text scaling
#
text_group6 = displayio.Group(scale=2, x=5, y=210)
text6 = adafruit_cursorcontrol.cursorcontrol.__version__
text_area6 = label.Label(terminalio.FONT, text=text6, color=0x000000)
text_group6.append(text_area6) # Subgroup for text scaling
splash.append(text_group1)
splash.append(text_group2)
</span><span style="color: red;"># initialize the mouse cursor object
# place under inner_sprite, text_group3/4/5/6, and over all other
mouse_cursor = adafruit_cursorcontrol.cursorcontrol.Cursor(
display, display_group=splash)</span><span style="color: black;">
splash.append(inner_sprite)
splash.append(text_group3)
splash.append(text_group4)
splash.append(text_group5)
splash.append(text_group6)
"""
# initialize the mouse cursor object
mouse_cursor = adafruit_cursorcontrol.cursorcontrol.Cursor(
display, display_group=splash)
"""
while True:
</span><span style="color: red;">offset_x = 0
offset_y = 0
delta_x = analog_A1.value-32768
delta_y = analog_A0.value-32768
if(delta_x >= 0):
if delta_x > 30000:
offset_x = 4
elif delta_x > 20000:
offset_x = 2
elif delta_x > 10000:
offset_x = 1
else:
if delta_x < -30000:
offset_x = -4
elif delta_x < -20000:
offset_x = -2
elif delta_x < -10000:
offset_x = -1
if(delta_y >= 0):
if delta_y > 30000:
offset_y = -4
elif delta_y > 20000:
offset_y = -2
elif delta_y > 10000:
offset_y = -1
else:
if delta_y < -30000:
offset_y = 4
elif delta_y < -20000:
offset_y = 2
elif delta_y < -10000:
offset_y = 1
mouse_cursor.x = mouse_cursor.x + offset_x
mouse_cursor.y = mouse_cursor.y + offset_y</span><span style="color: black;">
time.sleep(0.05)
print("~ bye ~")<span style="font-family: Times New Roman;"><span style="white-space: normal;">
</span></span></span></code></pre>
<div>
<b>cpyPico_st7789_240_cursor_delta_bitmap.py</b><br />implement custom cursor
bitmap.<br /><br />
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRdeTfUbosA6CtricggoZrq7FUzk44HR1KG8Rh_-umPX2_5VrFl_Qce1Go_1e9rxcbH3U98DvtJrdr0DRyGXYGJNDiNowGet5FKrDDoqp_zb3JrtCupzjsSb0UUeoK9LECqsmXEoULQKT5iaOHkNwSiqPuOBiOmYFgGp_9y9-FiZRxyV7rC5QOJdGJ/s1000/cpyPico_st7789_240_cursor_delta_bitmap.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="754" data-original-width="1000" height="241" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRdeTfUbosA6CtricggoZrq7FUzk44HR1KG8Rh_-umPX2_5VrFl_Qce1Go_1e9rxcbH3U98DvtJrdr0DRyGXYGJNDiNowGet5FKrDDoqp_zb3JrtCupzjsSb0UUeoK9LECqsmXEoULQKT5iaOHkNwSiqPuOBiOmYFgGp_9y9-FiZRxyV7rC5QOJdGJ/s320/cpyPico_st7789_240_cursor_delta_bitmap.jpg" width="320" /></a>
</div>
<br />
<pre style="border: 1px solid black;"><code><span style="color: black;">"""
Example of CircuitPython/RaspberryPi Pico
+ 240x240 ST7789 SPI RGB screen.
display cursor on displayio.
example to apply custom bitmap for cursor
Connection between Pico and
the IPS screen, with ST7789 SPI interface.
3V3 - BLK (backlight, always on)
GP11 - CS
GP12 - DC
GP13 - RES
GP15 - SDA
GP14 - SCL
3V3 - VCC
GND - GND
AnalogIn GP26_A0 connect to variable resistor for Y
AnalogIn GP26_A1 connect to variable resistor for X
"""
import os
import sys
import board
import time
import terminalio
import displayio
import busio
from adafruit_display_text import label
import adafruit_st7789
import adafruit_cursorcontrol.cursorcontrol
from analogio import AnalogIn
print("=====================================")
info = sys.implementation[0] + ' ' + \
os.uname()[3] + '\n' + \
'run on ' + os.uname()[4]
print(info)
print("=====================================")
print(adafruit_st7789.__name__ + " version: " +
adafruit_st7789.__version__)
print(adafruit_cursorcontrol.cursorcontrol.__name__
+ " version: "
+ adafruit_cursorcontrol.cursorcontrol.__version__)
print()
analog_A0 = AnalogIn(board.GP26_A0)
analog_A1 = AnalogIn(board.GP27_A1)
# Release any resources currently in use for the displays
displayio.release_displays()
tft_cs = board.GP11
tft_dc = board.GP12
tft_res = board.GP13
spi_mosi = board.GP15
spi_clk = board.GP14
display_width = 240
display_height = 240
"""
classbusio.SPI(clock: microcontroller.Pin,
MOSI: Optional[microcontroller.Pin] = None,
MISO: Optional[microcontroller.Pin] = None)
"""
spi = busio.SPI(spi_clk, MOSI=spi_mosi)
display_bus = displayio.FourWire(
spi, command=tft_dc, chip_select=tft_cs, reset=tft_res
)
display = adafruit_st7789.ST7789(display_bus,
width=display_width, height=display_height,
rowstart=80,
rotation=180)
# Make the display context
splash = displayio.Group()
display.show(splash)
color_bitmap = displayio.Bitmap(display_width, display_height, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0xA0A0A0
bg_sprite = displayio.TileGrid(color_bitmap,
pixel_shader=color_palette, x=0, y=0)
splash.append(bg_sprite)
# Draw a smaller inner rectangle
inner_bitmap = displayio.Bitmap(50, 180, 1)
inner_palette = displayio.Palette(1)
inner_palette[0] = 0x0000FF
inner_sprite = displayio.TileGrid(inner_bitmap,
pixel_shader=inner_palette, x=50, y=20)
#splash.append(inner_sprite)
info1 = sys.implementation[0] + ' ' + os.uname()[2]
info2 = 'run on ' + os.uname()[4]
# Draw labels for CircuitPython info
text_group1 = displayio.Group(scale=2, x=5, y=40)
text1 = info1
text_area1 = label.Label(terminalio.FONT, text=text1, color=0x000000)
text_group1.append(text_area1) # Subgroup for text scaling
#
text_group2 = displayio.Group(scale=1, x=5, y=70)
text2 = info2
text_area2 = label.Label(terminalio.FONT, text=text2, color=0xFFFFFF)
text_group2.append(text_area2) # Subgroup for text scaling
# Draw labels for adafruit_st7789
text_group3 = displayio.Group(scale=2, x=5, y=120)
text3 = adafruit_st7789.__name__
text_area3 = label.Label(terminalio.FONT, text=text3, color=0x000000)
text_group3.append(text_area3) # Subgroup for text scaling
#
text_group4 = displayio.Group(scale=2, x=5, y=150)
text4 = adafruit_st7789.__version__
text_area4 = label.Label(terminalio.FONT, text=text4, color=0xFF0000)
text_group4.append(text_area4) # Subgroup for text scaling
# Draw labels for adafruit_cursorcontrol.cursorcontrol
text_group5 = displayio.Group(scale=1, x=5, y=180)
text5 = adafruit_cursorcontrol.cursorcontrol.__name__
text_area5 = label.Label(terminalio.FONT, text=text5, color=0x000000)
text_group5.append(text_area5) # Subgroup for text scaling
#
text_group6 = displayio.Group(scale=2, x=5, y=210)
text6 = adafruit_cursorcontrol.cursorcontrol.__version__
text_area6 = label.Label(terminalio.FONT, text=text6, color=0x000000)
text_group6.append(text_area6) # Subgroup for text scaling
splash.append(text_group1)
splash.append(text_group2)
</span><span style="color: red;"># initialize the mouse cursor object
# create custom bitmap for cursor
bmp = displayio.Bitmap(20, 20, 3)
for i in range(0, 20):
bmp[i, (20-1)-i] = 1
bmp[(20-1)-i, (20-1)-i] = 1
for i in range(0, 20):
bmp[0, i] = 1
bmp[i, 0] = 1
# initialize the mouse cursor object
# place under inner_sprite, text_group3/4/5/6, and over all other
mouse_cursor = adafruit_cursorcontrol.cursorcontrol.Cursor(
display, display_group=splash, bmp=bmp)</span><span style="color: black;">
"""
#use default cursor
mouse_cursor = adafruit_cursorcontrol.cursorcontrol.Cursor(
display, display_group=splash)
"""
</span><span style="color: red;">cursor_bitmap = mouse_cursor.cursor_bitmap
print(cursor_bitmap, cursor_bitmap.width, "x", cursor_bitmap.height)
for by in range(0, cursor_bitmap.height):
s = str(by) + ":\t"
for bx in range(0, cursor_bitmap.width):
b = cursor_bitmap[bx, by]
if b == 0:
s = s + " " + " "
else:
s = s + str(b) + " "
print(s)</span><span style="color: black;">
splash.append(inner_sprite)
splash.append(text_group3)
splash.append(text_group4)
splash.append(text_group5)
splash.append(text_group6)
"""
# initialize the mouse cursor object
mouse_cursor = adafruit_cursorcontrol.cursorcontrol.Cursor(
display, display_group=splash)
"""
while True:
offset_x = 0
offset_y = 0
delta_x = analog_A1.value-32768
delta_y = analog_A0.value-32768
if(delta_x >= 0):
if delta_x > 30000:
offset_x = 4
elif delta_x > 20000:
offset_x = 2
elif delta_x > 10000:
offset_x = 1
else:
if delta_x < -30000:
offset_x = -4
elif delta_x < -20000:
offset_x = -2
elif delta_x < -10000:
offset_x = -1
if(delta_y >= 0):
if delta_y > 30000:
offset_y = -4
elif delta_y > 20000:
offset_y = -2
elif delta_y > 10000:
offset_y = -1
else:
if delta_y < -30000:
offset_y = 4
elif delta_y < -20000:
offset_y = 2
elif delta_y < -10000:
offset_y = 1
mouse_cursor.x = mouse_cursor.x + offset_x
mouse_cursor.y = mouse_cursor.y + offset_y
time.sleep(0.05)
print("~ bye ~")
</span></code></pre>
<br />
<br />
Erikhttp://www.blogger.com/profile/04983894331825656853noreply@blogger.com0tag:blogger.com,1999:blog-2462129950262077729.post-6852610143969740502022-05-08T07:49:00.001-07:002022-05-08T08:00:13.844-07:00OpenEuler 22.03 LTS (UKUI Desktop) run on Raspberry Pi 4<p>
<a href="https://www.openeuler.org/en/" target="_blank"><b>OpenEuler</b></a>
is an innovative platform nurtured by community collaboration. It aims to
build a unified and open OS that supports multiple processor architectures,
and to advance the hardware/software application ecosystem.<br /><b><br /></b>To download image of OpenEuler 22.03 LTS for Raspberry Pi, visit <a href="https://gitee.com/openeuler/raspberrypi" target="_blank">https://gitee.com/openeuler/raspberrypi</a> (You can switch to English here). It provide various desktops include
UKUI, DDE, Xfce and LXDE.<br /><br /><b>UKUI</b> is a Linux desktop built
by the KylinSoft software team over the years, primarily based on GTK and QT.
Compared to other UI interfaces, UKUI is easy to use. The components of UKUI
are small and low coupling, can run alone without relying on other suites. It
can provide user a friendly and efficient experience. UKUI supports both
x86_64 and aarch64 architectures.<br /><br />
</p>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_WeMf2dIbcMfjB2ItdqyXTJKJN_NuS_6ttNVTY-Ts2KAodU_5AIn4PeAKpNT7JAzQhtS3gQItnygTDJecFZDp6HQ6-epqQXWKuX9AxRyES98oYDSge7Sd-QnprBfimQmPGyH6kmguzByqfIpuuAnJsq9NhDgOG9cFe3bn2arsG7XJf3uWfKJRmHzd/s1280/OpenEuler%20Raspberry%20Pi%2001.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="1280" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_WeMf2dIbcMfjB2ItdqyXTJKJN_NuS_6ttNVTY-Ts2KAodU_5AIn4PeAKpNT7JAzQhtS3gQItnygTDJecFZDp6HQ6-epqQXWKuX9AxRyES98oYDSge7Sd-QnprBfimQmPGyH6kmguzByqfIpuuAnJsq9NhDgOG9cFe3bn2arsG7XJf3uWfKJRmHzd/w640-h360/OpenEuler%20Raspberry%20Pi%2001.png" width="640" /></a>
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjHkbhsog6EGhRJhbKlK3wyWHv3-GgKnv_fpLSBK-O2ymer66kcWV-Pgk1QhPjfsSvhLOhUya3hPPPdnDBmZgQxIrh1QkzKjfS61TZ3xV9Z4JDvlR9bLqQATd-AWaKIWDWIWL9Oazdvby7BxiZDOsFl01IRB2uRCMP6K6g7fY945Qwa3iSzm2rSlqJ/s1280/OpenEuler%20Raspberry%20Pi%2002.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="720" data-original-width="1280" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjHkbhsog6EGhRJhbKlK3wyWHv3-GgKnv_fpLSBK-O2ymer66kcWV-Pgk1QhPjfsSvhLOhUya3hPPPdnDBmZgQxIrh1QkzKjfS61TZ3xV9Z4JDvlR9bLqQATd-AWaKIWDWIWL9Oazdvby7BxiZDOsFl01IRB2uRCMP6K6g7fY945Qwa3iSzm2rSlqJ/w640-h360/OpenEuler%20Raspberry%20Pi%2002.png" width="640" /></a>
</div>
<br />
This video show the steps to download image of OpenEuler 22.03 LTS (UKUI Desktop) for Raspberry Pi, boot on Raspberry Pi 4B/4G and setup changing to English, and some more.
<br /><br /><center>
<iframe allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/vFvsi9ZTkCI" title="YouTube video player" width="560"></iframe>
</center>
<br /><div>~ <a href="https://docs.openeuler.org/en/" target="_blank">OpenEuler Document</a><br /><br /><br /></div>Erikhttp://www.blogger.com/profile/04983894331825656853noreply@blogger.com0tag:blogger.com,1999:blog-2462129950262077729.post-20292361934145536162022-04-10T05:15:00.002-07:002022-04-11T11:27:57.324-07:00Raspberry Pi Pico/CircuitPython act as IMU USB Mouse, read LSM303 Accelerometer and report as mouse movement.<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuGzlTcA8vOMM1TrcfwfpCaq10JuGcguawXqgEqejpQProCCqTyZ6rK_39PLX9RSgIsrt2rZzad1_xc_OHJPKNJKzWmBLLnYQFlayHecJyJChQwbaktfMO_7OHvbRAx2SkTvJfwKGjIsg4R2v9n2U7aGHLraOaUW2Sp9JGKBSqcw9GAFLJsdl9jcn0/s1000/CircuitPython%20IMU%20Mouse_01.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="606" data-original-width="1000" height="388" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuGzlTcA8vOMM1TrcfwfpCaq10JuGcguawXqgEqejpQProCCqTyZ6rK_39PLX9RSgIsrt2rZzad1_xc_OHJPKNJKzWmBLLnYQFlayHecJyJChQwbaktfMO_7OHvbRAx2SkTvJfwKGjIsg4R2v9n2U7aGHLraOaUW2Sp9JGKBSqcw9GAFLJsdl9jcn0/w640-h388/CircuitPython%20IMU%20Mouse_01.jpg" width="640" /></a>
</div>
<p>
Base on <b>cpyPico_lsm303_accel_inclinometer.py</b> exercise in last post
"<a href="https://helloraspberrypi.blogspot.com/2022/04/raspberry-pi-picocircuitpython-access.html">Raspberry Pi Pico/CircuitPython, access LSM303(Accelerometer/Magnetometer)
and L3GD20(Gyroscope)</a>", added with adafruit_hid.mouse library, it is modified to act as IMU
USB Mouse. User hold the 10DOF module, change orientation to move mouse
pointer.</p>
<center>
<iframe allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/Gac0fSIUYc4" title="YouTube video player" width="560"></iframe>
</center>
<br />
<b> cpyPico_lsm303_accel_inclinometer_mouse.py </b>
<pre style="border: 1px solid black;"><code><span style="color: black;">"""
Raspberry Pi Pico + LSM303
Act as usb_hid,
read Accelerometer and report mouse movement.
ref:
https://docs.circuitpython.org/projects/hid/en/latest/_modules/adafruit_hid/mouse.html
"""
import time
from math import atan2, degrees
import board
import adafruit_lsm303_accel
import busio
import usb_hid
from adafruit_hid.mouse import Mouse
mouse = Mouse(usb_hid.devices)
SDA=board.GP8
SCL=board.GP9
i2c = busio.I2C(SCL,SDA) # uses board.SCL and board.SDA
sensor = adafruit_lsm303_accel.LSM303_Accel(i2c)
def vector_2_degrees(x, y):
angle = degrees(atan2(y, x))
if angle < 0:
angle += 360
return angle
def get_inclination(_sensor):
x, y, z = _sensor.acceleration
return vector_2_degrees(x, z), vector_2_degrees(y, z)
while True:
angle_xz, angle_yz = get_inclination(sensor)
#print("XZ angle = {:6.2f}deg YZ angle = {:6.2f}deg".format(angle_xz, angle_yz))
print(angle_xz, angle_yz)
#LEFT/RIGHT
if angle_xz > 120:
mouse.move(x=+3)
elif angle_xz > 105:
mouse.move(x=+1)
elif angle_xz < 60:
mouse.move(x=-3)
elif angle_xz < 75:
mouse.move(x=-1)
#UP/DOWN
if angle_yz > 120:
mouse.move(y=-3)
elif angle_yz > 105:
mouse.move(y=-1)
elif angle_yz < 60:
mouse.move(y=+3)
elif angle_yz < 75:
mouse.move(y=+1)
time.sleep(0.02)
</span></code></pre>
related:<br />~ <a href="https://embedded-things.blogspot.com/2022/04/xiao-ble-sense-arduino-framework-imu.html" target="_blank">XIAO BLE Sense (Arduino framework) IMU USB Mouse</a><br /><br />Erikhttp://www.blogger.com/profile/04983894331825656853noreply@blogger.com0tag:blogger.com,1999:blog-2462129950262077729.post-61249417064102713562022-04-07T10:24:00.014-07:002022-04-10T05:16:23.413-07:00Raspberry Pi Pico/CircuitPython, access LSM303(Accelerometer/Magnetometer) and L3GD20(Gyroscope)<p>
The 10DOF module used in this exercise integrated with:<br />- LSM303DLHC
Accel/Mag<br />- L3GD20 Gyroscope<br />- BMP180 Temp/Baro<br />
</p>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtqZXSnirRapPNLL2lKP_Zl-194SRv5fEFB84shRujKdpBxbRhOezrJrYtw1y4H44X5Dyw1pDnWKoFuek07tANbfy_RnamoHbjODLBEyWQGa9_S0_MrkzrlXEX_1W2SR899_DqX843i3CbnzJVuxgDjoZ_yd1pLrJ1xALfCD-QBpNdE-LrH_0871nC/s1000/CircuitPython_RPi_LSM303_L3GD20_01.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="606" data-original-width="1000" height="388" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtqZXSnirRapPNLL2lKP_Zl-194SRv5fEFB84shRujKdpBxbRhOezrJrYtw1y4H44X5Dyw1pDnWKoFuek07tANbfy_RnamoHbjODLBEyWQGa9_S0_MrkzrlXEX_1W2SR899_DqX843i3CbnzJVuxgDjoZ_yd1pLrJ1xALfCD-QBpNdE-LrH_0871nC/w640-h388/CircuitPython_RPi_LSM303_L3GD20_01.jpg" width="640" /></a>
</div>
<br />Prepare Libraries:<br />Visit <a href="https://circuitpython.org/libraries" target="_blank">https://circuitpython.org/libraries</a>
to download matched CircuitPython Library Bundle. Copy needed libraries to
CircuitPython device /lib folder.<br /><br />
<center>
<iframe allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/R-P7FvzdoYk" title="YouTube video player" width="560"></iframe>
</center>
<br /><b><u>for LSM303(Accelerometer/Magnetometer)</u></b><br /><br /><b> cpyPico_lsm303_accel_inclinometer.py</b>, test LSM303
Accelerometer.
<pre style="border: 1px solid black;"><code><span style="color: black;"># SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
""" Display inclination data five times per second """
import time
from math import atan2, degrees
import board
import adafruit_lsm303_accel
</span><span style="color: red;">import busio</span><span style="color: black;">
</span><span style="color: red;">SDA=board.GP8
SCL=board.GP9</span><span style="color: black;">
</span><span style="color: red;">i2c = busio.I2C(SCL,SDA)</span><span style="color: black;"> # uses board.SCL and board.SDA
sensor = adafruit_lsm303_accel.LSM303_Accel(i2c)
def vector_2_degrees(x, y):
angle = degrees(atan2(y, x))
if angle < 0:
angle += 360
return angle
def get_inclination(_sensor):
x, y, z = _sensor.acceleration
return vector_2_degrees(x, z), vector_2_degrees(y, z)
while True:
angle_xz, angle_yz = get_inclination(sensor)
#print("XZ angle = {:6.2f}deg YZ angle = {:6.2f}deg".format(angle_xz, angle_yz))
</span><span style="color: red;">print(angle_xz, angle_yz)</span><span style="color: black;">
time.sleep(0.2)
</span></code></pre>
<br />next:<br />~ <a href="https://helloraspberrypi.blogspot.com/2022/04/raspberry-pi-picocircuitpython-act-as.html">act as IMU USB Mouse, read LSM303 Accelerometer and report as mouse movement</a>.<br /><br /><b> cpyPico_lsm303dlh_mag_compass.py</b>, test LSM303 Magnetometer.
<pre style="border: 1px solid black;"><code><span style="color: black;"># SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
""" Display compass heading data five times per second """
import time
from math import atan2, degrees
import board
import adafruit_lsm303dlh_mag
</span><span style="color: red;">import busio</span><span style="color: black;">
</span><span style="color: red;">SDA=board.GP8
SCL=board.GP9
i2c = busio.I2C(SCL, SDA)</span><span style="color: black;"> # uses board.SCL and board.SDA
sensor = adafruit_lsm303dlh_mag.LSM303DLH_Mag(i2c)
def vector_2_degrees(x, y):
angle = degrees(atan2(y, x))
if angle < 0:
angle += 360
return angle
def get_heading(_sensor):
magnet_x, magnet_y, _ = _sensor.magnetic
return vector_2_degrees(magnet_x, magnet_y)
while True:
print("heading: {:.2f} degrees".format(get_heading(sensor)))
time.sleep(0.2)
</span></code></pre>
<br /><b> cpyPico_st7789_240.py</b>, verify connection/function of st7789.
<pre style="border: 1px solid black;"><code><span style="color: black;">"""
Example of CircuitPython/RaspberryPi Pico
to display on 1.54" IPS 240x240 (RGB) screen
with ST7789 driver via SPI interface.
Connection between Pico and
the IPS screen, with ST7789 SPI interface.
3V3 - BLK (backlight, always on)
GP11 - CS
GP12 - DC
GP13 - RES
GP15 - SDA
GP14 - SCL
3V3 - VCC
GND - GND
"""
import os
import sys
import board
import time
import terminalio
import displayio
import busio
from adafruit_display_text import label
import adafruit_st7789
print("=====================================")
info = sys.implementation[0] + ' ' + \
os.uname()[3] + '\n' + \
'run on ' + os.uname()[4]
print(info)
print("=====================================")
print(adafruit_st7789.__name__ + " version: " + adafruit_st7789.__version__)
print()
# Release any resources currently in use for the displays
displayio.release_displays()
tft_cs = board.GP11
tft_dc = board.GP12
tft_res = board.GP13
spi_mosi = board.GP15
spi_clk = board.GP14
display_width = 240
display_height = 240
"""
classbusio.SPI(clock: microcontroller.Pin,
MOSI: Optional[microcontroller.Pin] = None,
MISO: Optional[microcontroller.Pin] = None)
"""
spi = busio.SPI(spi_clk, MOSI=spi_mosi)
display_bus = displayio.FourWire(
spi, command=tft_dc, chip_select=tft_cs, reset=tft_res
)
display = adafruit_st7789.ST7789(display_bus,
width=display_width, height=display_height,
rowstart=80,
rotation=180)
# Make the display context
splash = displayio.Group()
display.show(splash)
color_bitmap = displayio.Bitmap(display_width, display_height, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0xFF0000
bg_sprite = displayio.TileGrid(color_bitmap,
pixel_shader=color_palette, x=0, y=0)
splash.append(bg_sprite)
# Draw a smaller inner rectangle
inner_bitmap = displayio.Bitmap(133, 238, 1)
inner_palette = displayio.Palette(1)
inner_palette[0] = 0x0000FF
inner_sprite = displayio.TileGrid(inner_bitmap,
pixel_shader=inner_palette, x=1, y=1)
splash.append(inner_sprite)
info1 = sys.implementation[0] + ' ' + os.uname()[2]
info2 = 'run on ' + os.uname()[4]
# Draw a label
text_group1 = displayio.Group(scale=2, x=5, y=40)
text1 = info1
text_area1 = label.Label(terminalio.FONT, text=text1, color=0xFFFFFF)
text_group1.append(text_area1) # Subgroup for text scaling
# Draw a label
text_group2 = displayio.Group(scale=1, x=5, y=70)
text2 = info2
text_area2 = label.Label(terminalio.FONT, text=text2, color=0xFFFFFF)
text_group2.append(text_area2) # Subgroup for text scaling
# Draw a label
text_group3 = displayio.Group(scale=2, x=5, y=100)
text3 = adafruit_st7789.__name__
text_area3 = label.Label(terminalio.FONT, text=text3, color=0xFF0000)
text_group3.append(text_area3) # Subgroup for text scaling
# Draw a label
text_group4 = displayio.Group(scale=2, x=5, y=130)
text4 = adafruit_st7789.__version__
text_area4 = label.Label(terminalio.FONT, text=text4, color=0x00FF00)
text_group4.append(text_area4) # Subgroup for text scaling
splash.append(text_group1)
splash.append(text_group2)
splash.append(text_group3)
splash.append(text_group4)
time.sleep(2)
color_palette[0] = 0x00FF00
for c in range(00, 0xFF):
time.sleep(0.001)
col = ((0xFF-c)*0x0100) + c
color_palette[0] = col
time.sleep(0.001)
color_palette[0] = 0x0000FF
time.sleep(1)
for c in range(00, 0xFF):
time.sleep(0.001)
col = 0xFF-c
color_palette[0] = col
time.sleep(0.001)
color_palette[0] = 0x000000
time.sleep(1)
for c in range(00, 0xFF):
time.sleep(0.001)
col = (c * 0x010000) + (c*0x0100) + 0xFF
inner_palette[0] = col
time.sleep(0.001)
inner_palette[0] = 0xFFFFFF
time.sleep(1)
for c in range(0xFF, 0x00, -1):
time.sleep(0.001)
col = (c * 0x010000) + (c*0x0100) + c
inner_palette[0] = col
time.sleep(0.001)
inner_palette[0] = 0x000000
print("~ bye ~")
</span></code></pre>
<br /><b> cpyPico_st7789_compass.py</b>, read LSM303 Magnetometer, display on
ST7789 in compass form.
<pre style="border: 1px solid black;"><code><span style="color: black;">"""
Example of CircuitPython/RaspberryPi Pico
to display on 1.54" IPS 240x240 (RGB) screen
with ST7789 driver via SPI interface.
Read from lsm303dlh and display on ST7789 in compass form.
Connection between Pico and
the IPS screen, with ST7789 SPI interface.
3V3 - BLK (backlight, always on)
GP11 - CS
GP12 - DC
GP13 - RES
GP15 - SDA
GP14 - SCL
3V3 - VCC
GND - GND
Connection between Pico and 10DOF
3V3 - VIN
GND - GND
SCL - GP9
SDA - GP8
"""
import os
import sys
import board
import time
import terminalio
import displayio
import busio
from adafruit_display_text import label
from adafruit_display_shapes.circle import Circle
from adafruit_display_shapes.line import Line
import adafruit_st7789
from math import sin, cos, radians
from math import atan2, degrees
import adafruit_lsm303dlh_mag
#import gc
print("=====================================")
info = sys.implementation[0] + ' ' + \
os.uname()[3] + '\n' + \
'run on ' + os.uname()[4]
print(info)
print("=====================================")
print(adafruit_st7789.__name__ + " version: "
+ adafruit_st7789.__version__)
print(adafruit_lsm303dlh_mag.__name__ + " version: "
+ adafruit_lsm303dlh_mag.__version__)
print()
# Release any resources currently in use for the displays
displayio.release_displays()
SDA = board.GP8
SCL = board.GP9
i2c_lsm303dlh = busio.I2C(SCL, SDA)
sensor_lsm303dlh = adafruit_lsm303dlh_mag.LSM303DLH_Mag(i2c_lsm303dlh)
def vector_2_degrees(x, y):
angle = degrees(atan2(y, x))
if angle < 0:
angle += 360
return angle
def get_heading(_sensor):
magnet_x, magnet_y, _ = _sensor.magnetic
return vector_2_degrees(magnet_x, magnet_y)
tft_cs = board.GP11
tft_dc = board.GP12
tft_res = board.GP13
spi_mosi = board.GP15
spi_clk = board.GP14
display_width = 240
display_height = 240
spi = busio.SPI(spi_clk, MOSI=spi_mosi)
display_bus = displayio.FourWire(
spi, command=tft_dc, chip_select=tft_cs, reset=tft_res
)
display = adafruit_st7789.ST7789(display_bus,
width=display_width, height=display_height,
rowstart=80,
rotation=180)
# Make the display context
splash = displayio.Group()
display.show(splash)
color_bitmap = displayio.Bitmap(display_width, display_height, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0x000000
bg_sprite = displayio.TileGrid(color_bitmap,
pixel_shader=color_palette, x=0, y=0)
splash.append(bg_sprite)
cir_compass_cx = (int)(display_width/2)
cir_compass_cy = (int)(display_height/2)
cir_compass_r = 100
cir_compass = Circle(cir_compass_cx,
cir_compass_cy,
cir_compass_r,
fill=0x0000FF,
outline=0xFF0000)
splash.append(cir_compass)
# Draw a label
labelDir_group = displayio.Group(scale=2, x=5, y=40)
textDir = "0"
labelDir = label.Label(terminalio.FONT, text=textDir, color=0xFFFFFF)
labelDir_group.append(labelDir)
splash.append(labelDir_group)
dir_line_x1 = cir_compass_cx
dir_line_y1 = cir_compass_cy - cir_compass_r
dir_line = Line(cir_compass_cx,
cir_compass_cy,
dir_line_x1,
dir_line_y1,
0xFFFFFF)
splash.append(dir_line)
#-------------------------------
def drawDir(direction):
global splach
global dir_line
global labelDir
global display
labelDir.text = str(direction)
# depends on the alignmenet of your LSM303DLH and display
dirOffset = -(direction - 180)
x1 = (int)(cir_compass_cx +
(cir_compass_r * cos(radians(dirOffset))))
y1 = (int)(cir_compass_cy +
(cir_compass_r * sin(radians(dirOffset))))
splash.remove(dir_line)
dir_line = Line(cir_compass_cx,
cir_compass_cy,
x1,
y1,
0xFFFFFF)
splash.append(dir_line)
#print(gc.mem_free())
while True:
d = get_heading(sensor_lsm303dlh)
#print(d)
drawDir(d)
time.sleep(0.1)
print("~ bye ~")
</span></code></pre>
<br />
<b><u>For L3GD20(Gyroscope)</u></b><br /><br />This video show how to run on Raspberry Pi Pico/CircuitPython to
read L3GD20(Gyroscope), using modified
<a href="https://github.com/adafruit/Adafruit_CircuitPython_L3GD20" target="_blank">adafruit_l3gd20 library</a>.<br /><br />Basically, this exercise modified from CircuiyPython Libraries l3gd20_simpletest.py example, but with two proglem:<br />- unmatched I2C address, it'seasy to fix by adding parameter of address.<div>- RuntimeError: bad chip id (d3 != d4 or d7)<br /> The accepted chip id is hard coded in adafruit_l3gd20 library. To fix it, I download the <a href="http://adafruit_l3gd20.py" target="_blank">adafruit_l3gd20.py</a>, edit to add my chip id and save as my custom library in CircuitPython device /lib folder.<br /><br />
<center>
<iframe allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/l5a7QxnbOvA" title="YouTube video player" width="560"></iframe>
</center>
<br /><b>
cpyPico_I2C_Scan.py</b>, verify I2C devices.
<pre style="border: 1px solid black;"><code><span style="color: black;"># SPDX-FileCopyrightText: 2017 Limor Fried for Adafruit Industries
#
# SPDX-License-Identifier: MIT
"""CircuitPython I2C Device Address Scan"""
# If you run this and it seems to hang, try manually unlocking
# your I2C bus from the REPL with
# >>> import board
# >>> board.I2C().unlock()
import time
import board
import busio
SDA = board.GP8
SCL = board.GP9
i2c = busio.I2C(SCL, SDA)
# To use default I2C bus (most boards)
#i2c = board.I2C()
# To create I2C bus on specific pins
# import busio
# i2c = busio.I2C(board.SCL1, board.SDA1) # QT Py RP2040 STEMMA connector
# i2c = busio.I2C(board.GP1, board.GP0) # Pi Pico RP2040
while not i2c.try_lock():
pass
try:
while True:
print(
"I2C addresses found:",
[hex(device_address) for device_address in i2c.scan()],
)
time.sleep(2)
finally: # unlock the i2c bus when ctrl-c'ing out of the loop
i2c.unlock()
</span></code></pre>
<br /><b>
my_l3gd20.py</b>, modified from <a href="https://github.com/adafruit/Adafruit_CircuitPython_L3GD20" target="_blank">adafruit_l3gd20</a> to add supporting of our chip id, save to CircuitPython device /lib folder.
<pre style="border: 1px solid black;"><code><span style="color: black;"># SPDX-FileCopyrightText: 2018 Michael McWethy for Adafruit Industries
#
# SPDX-License-Identifier: MIT
# https://github.com/adafruit/Adafruit_CircuitPython_L3GD20
"""
`adafruit_l3gd20`
====================================================
Adafruit 9-DOF Absolute Orientation IMU Fusion Breakout - L3GD20
This is a CircuitPython driver for the Bosch L3GD20 nine degree of freedom
inertial measurement unit module with sensor fusion.
* Author(s): Michael McWethy
Implementation Notes
--------------------
**Hardware:**
* Adafruit `L3GD20H Triple-Axis Gyro Breakout Board <https://www.adafruit.com/product/1032>`_
**Software and Dependencies:**
* Adafruit CircuitPython firmware for the supported boards:
https://circuitpython.org/downloads
* Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register
"""
# imports
from math import radians
from struct import unpack
from micropython import const
from adafruit_register.i2c_struct import Struct
__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_L3GD20.git"
L3DS20_RANGE_250DPS = const(0)
L3DS20_RANGE_500DPS = const(1)
L3DS20_RANGE_2000DPS = const(2)
L3DS20_RATE_100HZ = const(0x00)
L3DS20_RATE_200HZ = const(0x40)
L3DS20_RATE_400HZ = const(0x80)
L3DS20_RATE_800HZ = const(0xC0)
_L3GD20_REGISTER_CTRL_REG1 = const(0x20)
_L3GD20_REGISTER_CTRL_REG4 = const(0x23)
# _L3GD20_REGISTER_OUT_X_L = const(0x28)
_L3GD20_REGISTER_OUT_X_L_X80 = const(0xA8)
_L3GD20_REGISTER_OUT_X_L_X40 = const(0x68)
_ID_REGISTER = const(0x0F)
</span><span style="color: red;">_MY_L3GD20_CHIP_ID = const(0xD3)</span><span style="color: black;">
_L3GD20_CHIP_ID = const(0xD4)
_L3GD20H_CHIP_ID = const(0xD7)
_L3GD20_SENSITIVITY_250DPS = 0.00875 ## Roughly 22/256 for fixed point match
_L3GD20_SENSITIVITY_500DPS = 0.0175 ## Roughly 45/256
_L3GD20_SENSITIVITY_2000DPS = 0.070 ## Roughly 18/256
# pylint: disable=no-member
class L3GD20:
"""
Driver for the L3GD20 3-axis Gyroscope sensor.
:param int rng: a range value one of:
* :const:`L3DS20_RANGE_250DPS`
* :const:`L3DS20_RANGE_500DPS`
* :const:`L3DS20_RANGE_2000DPS`
Defaults to :const:`L3DS20_RANGE_250DPS`
:param int rate: a rate value one of
* :const:`L3DS20_RATE_100HZ`
* :const:`L3DS20_RATE_200HZ`
* :const:`L3DS20_RATE_400HZ`
* :const:`L3DS20_RATE_800HZ`
Defaults to :const:`L3DS20_RATE_100HZ`
"""
def __init__(self, rng=L3DS20_RANGE_250DPS, rate=L3DS20_RATE_100HZ):
chip_id = self.read_register(_ID_REGISTER)
if chip_id not in (</span><span style="color: red;">_MY_L3GD20_CHIP_ID,</span><span style="color: black;"> _L3GD20_CHIP_ID, _L3GD20H_CHIP_ID):
raise RuntimeError(
"bad chip id (%x != </span><span style="color: red;">%x,</span><span style="color: black;"> %x or %x)"
% (chip_id, </span><span style="color: red;">_MY_L3GD20_CHIP_ID,</span><span style="color: black;"> _L3GD20_CHIP_ID, _L3GD20H_CHIP_ID)
)
if rng not in (L3DS20_RANGE_250DPS, L3DS20_RANGE_500DPS, L3DS20_RANGE_2000DPS):
raise ValueError(
"Range value must be one of L3DS20_RANGE_250DPS, "
"L3DS20_RANGE_500DPS, or L3DS20_RANGE_2000DPS"
)
# Set CTRL_REG1 (0x20)
# ====================================================================
# BIT Symbol Description Default
# --- ------ --------------------------------------------- -------
# 7-6 DR1#0 Output data rate
# 5-4 BW1#0 Bandwidth selection
# 3 PD 0 = Power-down mode, 1 = normal#sleep mode
# 2 ZEN Z-axis enable (0 = disabled, 1 = enabled)
# 1 YEN Y-axis enable (0 = disabled, 1 = enabled)
# 0 XEN X-axis enable (0 = disabled, 1 = enabled)
# Switch to normal mode and enable all three channels
self.write_register(_L3GD20_REGISTER_CTRL_REG1, rate | 0x0F)
# Set CTRL_REG2 (0x21)
# ====================================================================
# BIT Symbol Description Default
# --- ------ --------------------------------------------- -------
# 5-4 HPM1#0 High-pass filter mode selection
# 3-0 HPCF3..0 High-pass filter cutoff frequency selection
# Nothing to do ... keep default values
# ------------------------------------------------------------------
# Set CTRL_REG3 (0x22)
# ====================================================================
# BIT Symbol Description Default
# --- ------ --------------------------------------------- -------
# 7 I1_Int1 Interrupt enable on INT1 (0=disable,1=enable)
# 6 I1_Boot Boot status on INT1 (0=disable,1=enable)
# 5 H-Lactive Interrupt active config on INT1 (0=high,1=low)
# 4 PP_OD Push-Pull#Open-Drain (0=PP, 1=OD)
# 3 I2_DRDY Data ready on DRDY#INT2 (0=disable,1=enable)
# 2 I2_WTM FIFO wtrmrk int on DRDY#INT2 (0=dsbl,1=enbl)
# 1 I2_ORun FIFO overrun int on DRDY#INT2 (0=dsbl,1=enbl)
# 0 I2_Empty FIFI empty int on DRDY#INT2 (0=dsbl,1=enbl)
# Nothing to do ... keep default values
# -----------------------------------------------------------------
# Set CTRL_REG4 (0x23)
# ====================================================================
# BIT Symbol Description Default
# --- ------ --------------------------------------------- -------
# 7 BDU Block Data Update (0=continuous, 1=LSB#MSB)
# 6 BLE Big#Little-Endian (0=Data LSB, 1=Data MSB)
# 5-4 FS1#0 Full scale selection
# 00 = 250 dps
# 01 = 500 dps
# 10 = 2000 dps
# 11 = 2000 dps
# 0 SIM SPI Mode (0=4-wire, 1=3-wire)
# Adjust resolution if requested
if rng == L3DS20_RANGE_250DPS:
self.scale = _L3GD20_SENSITIVITY_250DPS
self.write_register(_L3GD20_REGISTER_CTRL_REG4, 0x00)
if rng == L3DS20_RANGE_500DPS:
self.scale = _L3GD20_SENSITIVITY_500DPS
self.write_register(_L3GD20_REGISTER_CTRL_REG4, 0x10)
if rng == L3DS20_RANGE_2000DPS:
self.scale = _L3GD20_SENSITIVITY_2000DPS
self.write_register(_L3GD20_REGISTER_CTRL_REG4, 0x20)
# ------------------------------------------------------------------
# Set CTRL_REG5 (0x24)
# ====================================================================
# BIT Symbol Description Default
# --- ------ --------------------------------------------- -------
# 7 BOOT Reboot memory content (0=normal, 1=reboot)
# 6 FIFO_EN FIFO enable (0=FIFO disable, 1=enable)
# 4 HPen High-pass filter enable (0=disable,1=enable)
# 3-2 INT1_SEL INT1 Selection config
# 1-0 OUT_SEL Out selection config
# Nothing to do ... keep default values
# ------------------------------------------------------------------
@property
def gyro(self):
"""
x, y, z angular momentum tuple floats, rescaled appropriately for
range selected in rad/s
"""
raw = self.gyro_raw
return tuple(radians(self.scale * v) for v in raw)
class L3GD20_I2C(L3GD20):
"""
Driver for L3GD20 Gyroscope using I2C communications
:param ~busio.I2C i2c: The I2C bus the device is connected to
:param int rng: range value. Defaults to :const:`0x68`
:param int rate: rate value. Defaults to :const:`L3DS20_RATE_100HZ`
**Quickstart: Importing and using the device**
Here is an example of using the :class:`L3GD20_I2C` class.
First you will need to import the libraries to use the sensor
.. code-block:: python
import board
import adafruit_l3gd20
Once this is done you can define your `board.I2C` object and define your sensor object
.. code-block:: python
i2c = board.I2C() # uses board.SCL and board.SDA
sensor = adafruit_l3gd20.L3GD20_I2C(i2c)
Now you have access to the :attr:`gyro` attribute
.. code-block:: python
gyro_data = sensor.gyro
"""
gyro_raw = Struct(_L3GD20_REGISTER_OUT_X_L_X80, "<hhh")
"""Gives the raw gyro readings, in units of rad/s."""
def __init__(
self, i2c, rng=L3DS20_RANGE_250DPS, address=0x6B, rate=L3DS20_RATE_100HZ
):
from adafruit_bus_device import ( # pylint: disable=import-outside-toplevel
i2c_device,
)
self.i2c_device = i2c_device.I2CDevice(i2c, address)
self.buffer = bytearray(2)
super().__init__(rng, rate)
def write_register(self, register, value):
"""
Update a register with a byte value
:param int register: which device register to write
:param value: a byte to write
"""
self.buffer[0] = register
self.buffer[1] = value
with self.i2c_device as i2c:
i2c.write(self.buffer)
def read_register(self, register):
"""
Returns a byte value from a register
:param register: the register to read a byte
"""
self.buffer[0] = register
with self.i2c_device as i2c:
i2c.write_then_readinto(self.buffer, self.buffer, out_end=1, in_start=1)
return self.buffer[1]
class L3GD20_SPI(L3GD20):
"""
Driver for L3GD20 Gyroscope using SPI communications
:param ~busio.SPI spi_busio: The SPI bus the device is connected to
:param ~digitalio.DigitalInOut cs: digital in/out to use as chip select signal
:param int rng: range value. Defaults to :const:`L3DS20_RANGE_250DPS`.
:param baudrate: SPI baud rate. Defaults to :const:`100000`
:param int rate: rate value. Defaults to :const:`L3DS20_RATE_100HZ`
**Quickstart: Importing and using the device**
Here is an example of using the :class:`L3GD20_SPI` class.
First you will need to import the libraries to use the sensor
.. code-block:: python
import board
import adafruit_l3gd20
Once this is done you can define your `board.SPI` object and define your sensor object
.. code-block:: python
spi = board.SPI()
sensor = adafruit_l3gd20.L3GD20_SPI(spi)
Now you have access to the :attr:`gyro` attribute
.. code-block:: python
gyro_data = sensor.gyro
"""
def __init__(
self,
spi_busio,
cs,
rng=L3DS20_RANGE_250DPS,
baudrate=100000,
rate=L3DS20_RATE_100HZ,
): # pylint: disable=too-many-arguments
from adafruit_bus_device import ( # pylint: disable=import-outside-toplevel
spi_device,
)
self._spi = spi_device.SPIDevice(spi_busio, cs, baudrate=baudrate)
self._spi_bytearray1 = bytearray(1)
self._spi_bytearray6 = bytearray(6)
super().__init__(rng, rate)
def write_register(self, register, value):
"""
Low level register writing over SPI, writes one 8-bit value
:param int register: which device register to write
:param value: a byte to write
"""
register &= 0x7F # Write, bit 7 low.
with self._spi as spi:
spi.write(bytes([register, value & 0xFF]))
def read_register(self, register):
"""
Low level register reading over SPI, returns a list of values
:param register: the register to read a byte
"""
register = (register | 0x80) & 0xFF # Read single, bit 7 high.
with self._spi as spi:
self._spi_bytearray1[0] = register
spi.write(self._spi_bytearray1)
spi.readinto(self._spi_bytearray1)
# Uncomment to dump bytearray:
# print("$%02X => %s" % (register, [hex(i) for i in self._spi_bytearray1]))
return self._spi_bytearray1[0]
def read_bytes(self, register, buffer):
"""
Low level register stream reading over SPI, returns a list of values
:param register: the register to read bytes
:param bytearray buffer: buffer to fill with data from stream
"""
register = (register | 0x80) & 0xFF # Read single, bit 7 high.
with self._spi as spi:
self._spi_bytearray1[0] = register
spi.write(self._spi_bytearray1)
spi.readinto(buffer)
@property
def gyro_raw(self):
"""Gives the dynamic rate raw gyro readings, in units rad/s."""
buffer = self._spi_bytearray6
self.read_bytes(_L3GD20_REGISTER_OUT_X_L_X40, buffer)
return tuple(radians(x) for x in unpack("<hhh", buffer))
</span></code></pre>
<br /><b>
cpyPico_l3gd20_simpletest.py</b>, exercise to read L3GD20 using our library.
<pre style="border: 1px solid black;"><code><span style="color: black;"># SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
import time
import board
import my_l3gd20
</span><span style="color: red;">import busio
SDA = board.GP8
SCL = board.GP9</span><span style="color: black;">
# Hardware I2C setup:
</span><span style="color: red;">I2C = busio.I2C(SCL, SDA)</span><span style="color: black;"> # uses board.SCL and board.SDA
# Initializes L3GD20 object using default range, 250dps
SENSOR = </span><span style="color: red;">my_l3gd20</span><span>.L3GD20_I2C(I2C, <span style="color: red;">address=0x69</span>)
# Initialize L3GD20 object using a custom range and output data rate (ODR).
# SENSOR = adafruit_l3gd20.L3GD20_I2C(
# I2C, rng=adafruit_l3gd20.L3DS20_RANGE_500DPS, rate=adafruit_l3gd20.L3DS20_RATE_200HZ
# )
# Possible values for rng are:
# adafruit_l3gd20.L3DS20_Range_250DPS, 250 degrees per second. Default range
# adafruit_l3gd20.L3DS20_Range_500DPS, 500 degrees per second
# adafruit_l3gd20.L3DS20_Range_2000DPS, 2000 degrees per second
# Possible values for rate are:
# adafruit_l3gd20.L3DS20_RATE_100HZ, 100Hz data rate. Default data rate
# adafruit_l3gd20.L3DS20_RATE_200HZ, 200Hz data rate
# adafruit_l3gd20.L3DS20_RATE_400HZ, 400Hz data rate
# adafruit_l3gd20.L3DS20_RATE_800HZ, 800Hz data rate
# Hardware SPI setup:
# import digitalio
# CS = digitalio.DigitalInOut(board.D5)
# SPIB = board.SPI()
# SENSOR = adafruit_l3gd20.L3GD20_SPI(SPIB, CS)
# SENSOR = adafruit_l3gd20.L3GD20_I2C(
# SPIB,
# CS,
# rng=adafruit_l3gd20.L3DS20_RANGE_500DPS,
# rate=adafruit_l3gd20.L3DS20_RATE_200HZ,
# )
while True:
#print("Angular Velocity (rad/s): {}".format(SENSOR.gyro))
<span style="color: red;">print(SENSOR.gyro[0], SENSOR.gyro[1], SENSOR.gyro[2])</span>
#print()
time.sleep(1)
</span></code></pre>
<br />
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
</div>Erikhttp://www.blogger.com/profile/04983894331825656853noreply@blogger.com0tag:blogger.com,1999:blog-2462129950262077729.post-17483057394328225822022-03-31T10:38:00.006-07:002022-03-31T10:48:21.409-07:00Raspberry Pi Pico/MicroPython generate QR Code and display on SSD1306 I2C OLED<p>
Run on Raspberry Pi Pico/MicroPython, to generate QR Code, and display on
SSD1306 128x64 I2C OLED.<br />
</p>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKMFUlh3ChCtKegojaN3fUD3q1tpP5RwN_vOwcG1bTkk0YttZQgao6zc1qrgOKmhurYPZrgUnyOiwDDatsWbZXWHeYgDLePYN8IO_l3x8UOhomtb7PHIwX_ryjPZmdQF_bILtZSo0Ru1KuPrTidNpOhe8rG8mW1U2sGH1m_fh8cuMtwSl3ypJaRgxA/s1000/RPiPico_MicroPython_miniqr_01.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="606" data-original-width="1000" height="388" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKMFUlh3ChCtKegojaN3fUD3q1tpP5RwN_vOwcG1bTkk0YttZQgao6zc1qrgOKmhurYPZrgUnyOiwDDatsWbZXWHeYgDLePYN8IO_l3x8UOhomtb7PHIwX_ryjPZmdQF_bILtZSo0Ru1KuPrTidNpOhe8rG8mW1U2sGH1m_fh8cuMtwSl3ypJaRgxA/w640-h388/RPiPico_MicroPython_miniqr_01.jpg" width="640" /></a>
</div>
<br />
<div>
I2C(0) is used to connect to SSD1306 I2C, scl=9 and sda=8.<br /><br />For
SSD1306 driver, visit
<a href="https://github.com/micropython/micropython/blob/master/drivers/display/ssd1306.py" target="_blank">https://github.com/micropython/micropython/blob/master/drivers/display/ssd1306.py</a>
to download ssd1306.py, save to Raspberry Pi Pico driver.<br /><br />For QR
Code,
<a href="https://github.com/JASchilz/uQR" target="_blank">JASchilz/uQR</a> is
used. Download uQR.py and save to Raspberry Pi Pico driver.<br /><br />
</div>
<center>
<iframe allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/OpRpZadnN_s" title="YouTube video player" width="560"></iframe>
</center>
<br />
mpyPico_i2c.py, simple verify I2C(0) pins and connection to SSD1306 I2C OLED.
<pre style="border: 1px solid black;"><code><span style="color: black;">import uos
import usys
print("====================================================")
print(usys.implementation[0],
str(usys.implementation[1][0]) + "." +
str(usys.implementation[1][1]) + "." +
str(usys.implementation[1][2]))
print(uos.uname()[3])
print("run on", uos.uname()[4])
print("====================================================")
i2c0 = machine.I2C(0)
print(i2c0)
print("Available i2c devices: "+ str(i2c0.scan()))
print("~ bye ~")
</span></code></pre>
<br />
mpyPico_ssd1306.py, simple test program for SSD1306 I2C OLED.
<pre style="border: 1px solid black;"><code><span style="color: black;">"""
Run on Raspbery Pi Pico/MicroPython
display on ssd1306 I2C OLED
connec ssd1306 using I2C(0)
scl=9
sda=8
- Libs needed:
ssd1306 library
https://github.com/micropython/micropython/blob/master/drivers/display/ssd1306.py
"""
import uos
import usys
from ssd1306 import SSD1306_I2C
print("====================================================")
print(usys.implementation[0],
str(usys.implementation[1][0]) + "." +
str(usys.implementation[1][1]) + "." +
str(usys.implementation[1][2]))
print(uos.uname()[3])
print("run on", uos.uname()[4])
print("====================================================")
i2c0 = machine.I2C(0)
print(i2c0)
print("Available i2c devices: "+ str(i2c0.scan()))
WIDTH = 128
HEIGHT = 64
oled = SSD1306_I2C(WIDTH, HEIGHT, i2c0)
oled.fill(0)
oled.text(usys.implementation[0], 0, 0)
strVersion = str(usys.implementation[1][0]) + "." + \
str(usys.implementation[1][1]) + "." + \
str(usys.implementation[1][2])
oled.text(strVersion, 0, 10)
oled.text(uos.uname()[3], 0, 20)
oled.text(uos.uname()[4], 0, 40)
oled.show()
</span></code></pre>
<br />
mpyPico_ssd1306_uQR.py, generate QR Code using uQR.py, and display on SSD1306 I2C OLED.
<pre style="border: 1px solid black;"><code><span style="color: black;">"""
Run on Raspbery Pi Pico/MicroPython
to generate QR code using uQR,
and display on ssd1306 I2C OLED
- Libs needed:
ssd1306 library
https://github.com/micropython/micropython/blob/master/drivers/
display/ssd1306.py
JASchilz/uQR:
https://github.com/JASchilz/uQR
remark:
in the original example on uQR to display on ssd1306, scale of 2 is used.
It's found:
- If the data is too long, the small 128x64 OLED cannot display the whole matrix.
- In my test using my phone, scale of 1 is more easy to recognize.
Such that I use scale of 1 inside the loop to generate qr code.
"""
from uos import uname
from usys import implementation
from machine import I2C
from time import sleep
from ssd1306 import SSD1306_I2C
from uQR import QRCode
print("====================================================")
print(implementation[0],
str(implementation[1][0]) + "." +
str(implementation[1][1]) + "." +
str(implementation[1][2]))
print(uname()[3])
print("run on", uname()[4])
print("====================================================")
i2c0 = I2C(0)
print(i2c0)
print("Available i2c devices: "+ str(i2c0.scan()))
WIDTH = 128
HEIGHT = 64
oled = SSD1306_I2C(WIDTH, HEIGHT, i2c0)
oled.fill(0)
oled.text("RPi Pico", 0, 0)
oled.text("MicroPython", 0, 10)
oled.text("OLED(ssd1306)", 0, 20)
oled.text("uQR exercise", 0, 40)
oled.show()
sleep(5)
qr = QRCode()
qr.add_data("uQR example")
matrix = qr.get_matrix()
print("version:", qr.version)
print("len of matrix", len(matrix))
oled.fill(1)
for y in range(len(matrix)*2): # Scaling the bitmap by 2
for x in range(len(matrix[0])*2): # because my screen is tiny.
value = not matrix[int(y/2)][int(x/2)] # Inverting the values because
oled.pixel(x, y, value) # black is `True` in the matrix.
oled.show()
while True:
userinput = input("\nEnter something: ")
if userinput == "":
break
print(userinput)
qr.clear()
qr.add_data(userinput)
matrix = qr.get_matrix()
print("version:", qr.version)
print("len of matrix", len(matrix))
oled.fill(1)
scale = 1
for y in range(len(matrix)*scale):
for x in range(len(matrix[0])*scale):
value = not matrix[int(y/scale)][int(x/scale)]
oled.pixel(x, y, value)
oled.show()
print("~ bye ~")
</span></code></pre>
<br />
mpyPico_simpletest_uQR.py, generate QR Code and display on REPL.
<pre style="border: 1px solid black;"><code><span style="color: black;">"""
Run on Raspbery Pi Pico/MicroPython
to generate QR code using uQR,
and display on screen
- Libs needed:
JASchilz/uQR:
https://github.com/JASchilz/uQR
"""
from uos import uname
from usys import implementation
from usys import stdout
from uQR import QRCode
print("====================================================")
print(implementation[0],
str(implementation[1][0]) + "." +
str(implementation[1][1]) + "." +
str(implementation[1][2]))
print(uname()[3])
print("run on", uname()[4])
print("====================================================")
# For drawing filled rectangles to the console:
stdout = stdout
WHITE = "\x1b[1;47m \x1b[40m"
BLACK = " "
NORMAL = '\033[1;37;0m'
def print_QR(uqr):
qr_matrix = uqr.get_matrix()
print("version:", uqr.version)
qr_height = len(qr_matrix)
qr_width = len(qr_matrix[0])
print("qr_height: ", qr_height)
print("qr_width: ", qr_width)
for _ in range(4):
for _ in range(qr_width + 8): #margin on top
stdout.write(WHITE)
print()
for y in range(qr_height):
stdout.write(WHITE * 4) #margin on right
for x in range(len(matrix[0])):
value = qr_matrix[int(y)][int(x)]
if value == True:
stdout.write(BLACK)
else:
stdout.write(WHITE)
stdout.write(WHITE * 4) #margin on left
print()
for _ in range(4):
for _ in range(qr_width + 8): #margin on bottom
stdout.write(WHITE)
print()
print(NORMAL)
qr = QRCode()
qr.add_data("uQR example")
matrix = qr.get_matrix()
print_QR(qr)
while True:
userinput = input("\nEnter something: ")
if userinput == "":
break
print(userinput)
qr.clear()
qr.add_data(userinput)
matrix = qr.get_matrix()
print_QR(qr)
print("~ bye ~")
</span></code></pre>
~ <a href="https://helloraspberrypi.blogspot.com/2021/01/first-power-up-raspberry-pi-pico-on.html">More exercise for Raspberry Pi Pico</a><br /><br />Erikhttp://www.blogger.com/profile/04983894331825656853noreply@blogger.com0tag:blogger.com,1999:blog-2462129950262077729.post-78888290351299174272022-03-15T10:15:00.003-07:002022-03-15T10:15:42.809-07:00Raspberry Pi Pico online simulator<p>Wokwi is an online Electronics simulator. You can use it to simulate Arduino, ESP32, and many other popular boards, parts and sensors.<br /><br />Here is a <a href="https://wokwi.com/projects/new/pi-pico-sdk" target="_blank">Raspberry Pi Pico (SDK) online simulator</a>.<br /></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEi6gtUvREP5c7498RVQnPNS1RpP1cVWJ3u4ZXLaGAZedcNHd-v_gKYu1eM8uSS2vy41xaIwnLVtf-1OwUpl6EqHMkrYLsbLiKLKADM5t6NMSfq1YvHkNM1cxf7BmX4By7O8PTrjcYk2aWnPHmuzcuUxpqlWFPbfbNial7RortlZ_vq_ZvgHzdrZBDqw=s2000" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1200" data-original-width="2000" height="384" src="https://blogger.googleusercontent.com/img/a/AVvXsEi6gtUvREP5c7498RVQnPNS1RpP1cVWJ3u4ZXLaGAZedcNHd-v_gKYu1eM8uSS2vy41xaIwnLVtf-1OwUpl6EqHMkrYLsbLiKLKADM5t6NMSfq1YvHkNM1cxf7BmX4By7O8PTrjcYk2aWnPHmuzcuUxpqlWFPbfbNial7RortlZ_vq_ZvgHzdrZBDqw=w640-h384" width="640" /></a></div><br />Erikhttp://www.blogger.com/profile/04983894331825656853noreply@blogger.com0tag:blogger.com,1999:blog-2462129950262077729.post-37122025088340260482022-02-23T22:07:00.001-08:002022-02-23T22:07:13.827-08:00Raspberry Pi Pico/MicroPython: get MicroPython version programmatically<p>
A simple exercise run on Raspberry Pi Pico/MicroPython to get installed
MicroPython version programmatically.
</p>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/a/AVvXsEjuTc7e5jkbRMSw6HM8cm2r9NgbZv1_r25xHaSF1FIsQOCSoQAi7bQowftOMZByLNNsNWok9z-TQ7N6Og98yHVeSwRjHgjfOSfm4dB5TBKOZh9HWi0saJm4bugC38fNHLTH8C-5FMyP76ocIc6NqUQRWNxBicYBnxkjorlB5opF_5M3Z_tz1OxV0vku=s1800" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1080" data-original-width="1800" height="384" src="https://blogger.googleusercontent.com/img/a/AVvXsEjuTc7e5jkbRMSw6HM8cm2r9NgbZv1_r25xHaSF1FIsQOCSoQAi7bQowftOMZByLNNsNWok9z-TQ7N6Og98yHVeSwRjHgjfOSfm4dB5TBKOZh9HWi0saJm4bugC38fNHLTH8C-5FMyP76ocIc6NqUQRWNxBicYBnxkjorlB5opF_5M3Z_tz1OxV0vku=w640-h384" width="640" /></a>
</div>
<br />
<p>mpyPico_info.py</p><pre style="border: 1px solid black;"><code><span style="color: black;">import uos
import usys
class color:
BLACK = '\033[1;30;48m'
RED = '\033[1;31;48m'
GREEN = '\033[1;32;48m'
YELLOW = '\033[1;33;48m'
BLUE = '\033[1;34;48m'
MAGENTA = '\033[1;35;48m'
CYAN = '\033[1;36;48m'
END = '\033[1;37;0m'
#print(uos.uname())
#print(usys.implementation)
print("====================================================")
print(color.BLUE, usys.implementation[0],
str(usys.implementation[1][0]) + "." +
str(usys.implementation[1][1]) + "." +
str(usys.implementation[1][2]), color.END)
print(uos.uname()[3])
print("run on", color.RED, uos.uname()[4], color.END)
print("====================================================")
</span></code></pre>
<p><br /></p>
<hr />
<br />
~ <a href="https://helloraspberrypi.blogspot.com/2021/01/first-power-up-raspberry-pi-pico-on.html">more exercises for Raspberry Pi Pico</a><br />
<br />
Erikhttp://www.blogger.com/profile/04983894331825656853noreply@blogger.com0tag:blogger.com,1999:blog-2462129950262077729.post-65650460158509503142022-02-05T11:25:00.008-08:002022-02-27T08:09:47.473-08:00How to check running Raspberry Pi OS version, 32 bit or 64 bit.<div>To check the bit size (32 bit or 64 bit) of the running Raspberry Pi OS, you can enter the commands:</div><div><br /></div><div><b>$ uname -m</b></div><div>aarch64</div><div><br /></div><div>or:</div><div><br /></div><div><b>$ arch</b></div><div>aarch64</div><div><br /></div><div>You can also check the bit size of the Linux kernel with:</div><div><br /></div><div><b>$ getconf LONG_BIT</b></div><div>64</div><div><br /></div><div>Tested on Raspberry Pi 4B running Raspberry Pi OS 64-bit (bullseye):</div>
<div class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEh89bXH1-rjIW0uS215Dd58_nNT2L0M_w_imUL5KjRVKTzrx1FS4XnTzglM98rU8qB09acjOnl_C_uKz9_PthRu_rptEU5OIqPBqdlKVswvocJgL38dbVZ5Zirjfunmohh-Z0Dy5lBdyeRAkrLQxAJ8M1cdCKbCc74fYjCYS85-qrClGokXAQw-t3VOeg=s1920" style="display: block; padding: 1em 0px; text-align: center;"><img alt="" border="0" data-original-height="1080" data-original-width="1920" src="https://blogger.googleusercontent.com/img/a/AVvXsEh89bXH1-rjIW0uS215Dd58_nNT2L0M_w_imUL5KjRVKTzrx1FS4XnTzglM98rU8qB09acjOnl_C_uKz9_PthRu_rptEU5OIqPBqdlKVswvocJgL38dbVZ5Zirjfunmohh-Z0Dy5lBdyeRAkrLQxAJ8M1cdCKbCc74fYjCYS85-qrClGokXAQw-t3VOeg=s600" width="600" /></a></div>
<br />
<div>Tested on Raspberry Pi 4B running Raspberry Pi OS 32-bit (buster):</div><div><br /></div><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEit8GSwtmgPreF0tWp4ZzAK5fVzKXWf9DOI5NGktZaratKnjDOrTzBbRh8a2AabmonpWyZBaGh2Md_5WIcfvTk6HNYuLnjF5_Btq24mHmkM6raVseuR8nQs34YhZ62nSrgrtSUh60TeF-JUPmwvtjwjkMveh0Wg3kR6krs3qwB0AY6L98-XwON8a9Ovmg=s1800" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1080" data-original-width="1800" height="384" src="https://blogger.googleusercontent.com/img/a/AVvXsEit8GSwtmgPreF0tWp4ZzAK5fVzKXWf9DOI5NGktZaratKnjDOrTzBbRh8a2AabmonpWyZBaGh2Md_5WIcfvTk6HNYuLnjF5_Btq24mHmkM6raVseuR8nQs34YhZ62nSrgrtSUh60TeF-JUPmwvtjwjkMveh0Wg3kR6krs3qwB0AY6L98-XwON8a9Ovmg=w640-h384" width="640" /></a></div><br /><div><br /></div>
rpiihttp://www.blogger.com/profile/11029985001257500904noreply@blogger.com0tag:blogger.com,1999:blog-2462129950262077729.post-58139653436146454042021-11-29T04:54:00.006-08:002021-11-29T04:54:47.720-08:00Simple exercise to control GPIO on Raspberry Pi, C and Python<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh59khSg7AEPpFbQwMYgXlbvuR9YR2bqegbfD0RXpKM40PkTDopZYU5EtY_-bMoyKzNHx-zh8zQzxs8ciJ70io0w1yeTBs0p15qYQ2MJURw6W_5rBb1bzFc5poPIDLH319nd2-SEnFr1LU/s800/Raspberry+Pi+GPIO.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="604" data-original-width="800" height="484" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh59khSg7AEPpFbQwMYgXlbvuR9YR2bqegbfD0RXpKM40PkTDopZYU5EtY_-bMoyKzNHx-zh8zQzxs8ciJ70io0w1yeTBs0p15qYQ2MJURw6W_5rBb1bzFc5poPIDLH319nd2-SEnFr1LU/w640-h484/Raspberry+Pi+GPIO.jpg" width="640" /></a>
</div>
<p>Simple exercise to control GPIO on Raspberry Pi, tested on Raspberry Pi Zero 2
W running "Raspbian GNU/Linux 11 (bullseye)".
</p>
blink.c, in C language:<pre style="border: 1px solid black;"><code><span style="color: black;">#include <stdio.h>
#include <pigpio.h>
#define led 17
int main(void){
printf("- IO Test on\n");
printf("- Raspberry Pi Zero 2 W\n");
gpioInitialise();
gpioSetMode(led, PI_OUTPUT);
while(1){
gpioWrite(led, 1);
time_sleep(1);
gpioWrite(led, 0);
time_sleep(1);
}
}
</span></code></pre>
To compile it link to pigpio library:
<div>
<b>$ gcc blink.c -o blink -lpigpio</b><br /><br />To run it with sudo:<br /><b>$ sudo ./blink</b>
</div>
<div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidTjjPzG-waczKKSc1hDe9v9BKMaN-eUhubaG2t72Ah-LrT0kTc2jRg-qdkkhzxMe1XMDflEQxVCr9skCkadeRJPYPdyKU8F3vAAlLeyRmNvME90057hfYbYrqM897w7nj_mvqs5PA8CU/s1366/blink.c.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="768" data-original-width="1366" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidTjjPzG-waczKKSc1hDe9v9BKMaN-eUhubaG2t72Ah-LrT0kTc2jRg-qdkkhzxMe1XMDflEQxVCr9skCkadeRJPYPdyKU8F3vAAlLeyRmNvME90057hfYbYrqM897w7nj_mvqs5PA8CU/w640-h360/blink.c.png" width="640" /></a>
</div>
<br />
</div><b>
py_LED.py</b>, in Python:<pre style="border: 1px solid black;"><code><span style="color: black;">from gpiozero import LED
from time import sleep
led = LED(17)
while True:
led.on()
sleep(1)
led.off()
sleep(1)
</span></code></pre>
<br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKY5_C3RpuWsrQz1Us_op2fm6ahOm6lOgEJul8HKDBSh3wKeZdsTdHADrrBrFz6qV-Tuvhm6X4AFKplOyllm1Kwa2mbuXjurVeWDlaNU2-_3by2sBrBnn4jlt-lntostUQhlIzSOaU6aE/s1366/py_LED.py.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="768" data-original-width="1366" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKY5_C3RpuWsrQz1Us_op2fm6ahOm6lOgEJul8HKDBSh3wKeZdsTdHADrrBrFz6qV-Tuvhm6X4AFKplOyllm1Kwa2mbuXjurVeWDlaNU2-_3by2sBrBnn4jlt-lntostUQhlIzSOaU6aE/w640-h360/py_LED.py.png" width="640" /></a></div><br />Erikhttp://www.blogger.com/profile/04983894331825656853noreply@blogger.com0tag:blogger.com,1999:blog-2462129950262077729.post-33535562276001255782021-11-18T07:36:00.005-08:002021-11-29T04:56:40.647-08:00My Raspberry Pi Zero 2 W<p> My Raspberry Pi Zero 2 W received:</p>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLAHOiWKraqjjNHAs5kRsUfsn0W0Y4oB0DSAsx7jj8gc9YN2XtQkfYV3S-AzTZA__SEIBB5BMeAjmK2PDs3HtMwAQsMsux_sEpr_Ds107mdapX5rgQihXGPKcUNtaEkzELIeX0tx_68DU/s800/Raspberry+Pi+Zero+2+W_01.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="604" data-original-width="800" height="484" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLAHOiWKraqjjNHAs5kRsUfsn0W0Y4oB0DSAsx7jj8gc9YN2XtQkfYV3S-AzTZA__SEIBB5BMeAjmK2PDs3HtMwAQsMsux_sEpr_Ds107mdapX5rgQihXGPKcUNtaEkzELIeX0tx_68DU/w640-h484/Raspberry+Pi+Zero+2+W_01.jpg" width="640" /></a>
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhc24zPHNLmkq9blR0Rh5BKkCzBT5LVfGUqUiKGNrAe5DhMe5e0uxWbFUfiAnp0_vZ907EKJMV06HK-LE9ySdRdDitqEV2Zx46OhfrtMP3DCTFM2RPefvCkgKQTgmVraJ1wJgITUHwsvcE/s800/Raspberry+Pi+Zero+2+W_02.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="604" data-original-width="800" height="484" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhc24zPHNLmkq9blR0Rh5BKkCzBT5LVfGUqUiKGNrAe5DhMe5e0uxWbFUfiAnp0_vZ907EKJMV06HK-LE9ySdRdDitqEV2Zx46OhfrtMP3DCTFM2RPefvCkgKQTgmVraJ1wJgITUHwsvcE/w640-h484/Raspberry+Pi+Zero+2+W_02.jpg" width="640" /></a>
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxk1z7f3OxbNR2hGiNO3v3Iv-AgVtRJU2NBss-OioF56kEuquHDyRwxBt_Z4WRKWHbVHGhCUP_WXtoqMatdnWOjLNI5Byq8UsQjcphh0WC64s_NGOItlpmdR8342npm_Zkhhohi8hs1oY/s800/Raspberry+Pi+Zero+2+W_03.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="604" data-original-width="800" height="484" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxk1z7f3OxbNR2hGiNO3v3Iv-AgVtRJU2NBss-OioF56kEuquHDyRwxBt_Z4WRKWHbVHGhCUP_WXtoqMatdnWOjLNI5Byq8UsQjcphh0WC64s_NGOItlpmdR8342npm_Zkhhohi8hs1oY/w640-h484/Raspberry+Pi+Zero+2+W_03.jpg" width="640" /></a>
</div>
<br />
<p>
Raspberry Pi Zero 2 W installed new 32-bit Raspberry Pi OS (bullseye), running
neofetch:
</p>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgCURlx_NssD9t8xjTepPbaormsrQBpQ74KGLEw3IuZKx7-AdeZSzRz1uNwBjG-_VoZqOgq3Dx6ImtRz58O0_EAsPjNkCwF6b9GFEV3m5S8HpSvn0_2_iDoWQtd0zUeEV3NPMz6Vw6LJ4/s1366/Raspberry+Pi+Zero+2+W_neofetch.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="768" data-original-width="1366" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgCURlx_NssD9t8xjTepPbaormsrQBpQ74KGLEw3IuZKx7-AdeZSzRz1uNwBjG-_VoZqOgq3Dx6ImtRz58O0_EAsPjNkCwF6b9GFEV3m5S8HpSvn0_2_iDoWQtd0zUeEV3NPMz6Vw6LJ4/w640-h360/Raspberry+Pi+Zero+2+W_neofetch.png" width="640" /></a>
</div>
<p><br /></p>
<hr />
Check Board name and version using cpuinfo:
<pre style="border: 1px solid black;"><code><span>pi@raspberrypi:~ $ <b><span style="color: red;">cat /proc/cpuinfo</span></b>
processor : 0
model name : ARMv7 Processor rev 4 (v7l)
BogoMIPS : 38.40
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4
processor : 1
model name : ARMv7 Processor rev 4 (v7l)
BogoMIPS : 38.40
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4
processor : 2
model name : ARMv7 Processor rev 4 (v7l)
BogoMIPS : 38.40
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4
processor : 3
model name : ARMv7 Processor rev 4 (v7l)
BogoMIPS : 38.40
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xd03
CPU revision : 4
Hardware : BCM2835
Revision : 902120
Serial : 000000009470cd94
Model : Raspberry Pi Zero 2 Rev 1.0
</span></code></pre>
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkdE7VNO74iy_v5MGIUOsVH6PfvHtNNdm4xxu8Yji2j9diivnMjLsBaWl075f4l9bfUrzvvtJGhR182teQEcf_nMmE94brooesGWzYPDpMlCJcbPLdGbmv3wBXNdXL6aTOJBTPQtD_KbQ/s1366/cpuinfo.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="768" data-original-width="1366" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkdE7VNO74iy_v5MGIUOsVH6PfvHtNNdm4xxu8Yji2j9diivnMjLsBaWl075f4l9bfUrzvvtJGhR182teQEcf_nMmE94brooesGWzYPDpMlCJcbPLdGbmv3wBXNdXL6aTOJBTPQtD_KbQ/w640-h360/cpuinfo.png" width="640" /></a></div><div><br /></div>
Check OS version using /etc/os-release:<br />
<pre style="border: 1px solid black;"><code><span>pi@raspberrypi:~ $ <b><span style="color: red;">cat /etc/os-release</span></b>
PRETTY_NAME="Raspbian GNU/Linux 11 (bullseye)"
NAME="Raspbian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
</span></code></pre>
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCX2FZGD0xbo_TE_mCw19bRwaBawyERwe9RSLJpRFZzMB1GguJR4yGuOIAC9qlATwA7zeSuMQwLmen_FxfPM_UaO3eFiHbbqqsBP_y9y1jgc7o6vPsK5YZf6s3eh6GySsDGWqkt8QIaec/s1366/os-release.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="768" data-original-width="1366" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCX2FZGD0xbo_TE_mCw19bRwaBawyERwe9RSLJpRFZzMB1GguJR4yGuOIAC9qlATwA7zeSuMQwLmen_FxfPM_UaO3eFiHbbqqsBP_y9y1jgc7o6vPsK5YZf6s3eh6GySsDGWqkt8QIaec/w640-h360/os-release.png" width="640" /></a></div><br /><div><br /></div><br />
<hr />
<p>Related:</p><p></p><ul style="text-align: left;"><li><a href="https://helloraspberrypi.blogspot.com/2021/11/simple-exercise-to-control-gpio-on.html">Test GPIO Control</a></li></ul><p></p><p>Documents:<br /></p>
<ul style="text-align: left;">
<li>
<a href="https://www.raspberrypi.com/documentation/computers/getting-started.html" target="_blank">Getting started guide</a>
</li>
<li>
<a href="https://datasheets.raspberrypi.com/rpizero2/raspberry-pi-zero-2-w-product-brief.pdf" target="_blank">Raspberry Pi Zero 2 W product brief</a>
</li>
</ul>
<br /><br />
<p></p>
Erikhttp://www.blogger.com/profile/04983894331825656853noreply@blogger.com0tag:blogger.com,1999:blog-2462129950262077729.post-22465712466302321872021-10-16T10:48:00.003-07:002021-10-16T10:48:30.509-07:00CircuitPython 7.0.0 run on Raspberry Pi Pico RP2040<p> CircuitPython 7.0.0 run on Raspberry Pi Pico RP2040:</p>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRKrZqtYPY0VTp4E2SxIFvI-n5FIp624vTPYECdL0iwLgjl4r20hBSK8GIHqFXlwk0tFLsbjESFlaOL7LmKrATPm_-Fj-mNGy3KnkLufxwB2FuoBVy6tLHojKTWaWiNEeRVS7MC_oCCeQ/s2000/cpyPico_info.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1200" data-original-width="2000" height="384" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRKrZqtYPY0VTp4E2SxIFvI-n5FIp624vTPYECdL0iwLgjl4r20hBSK8GIHqFXlwk0tFLsbjESFlaOL7LmKrATPm_-Fj-mNGy3KnkLufxwB2FuoBVy6tLHojKTWaWiNEeRVS7MC_oCCeQ/w640-h384/cpyPico_info.jpg" width="640" /></a></div>
<pre style="border: 1px solid black;"><code><span style="color: black;">"""
CircuitPython 7 exercise run on Raspberry Pi Pico PR2040,
get system info.
"""
import board
import sys
import os
import microcontroller
# ref:
# The entire table of ANSI color codes working in C:
# https://gist.github.com/RabaDabaDoba/145049536f815903c79944599c6f952a
class color:
RED = '\033[1;31;48m'
BLUE = '\033[1;34;48m'
BLACK = '\033[1;30;48m'
END = '\033[1;37;0m'
print(board.board_id)
print(sys.implementation[0] + ' ' +
str(sys.implementation[1][0]) +'.'+
str(sys.implementation[1][1]) +'.'+
str(sys.implementation[1][2]))
print("=====================================")
info = color.RED + \
sys.implementation[0] + ' ' + \
os.uname()[3] + color.END + '\n' + \
'run on ' + color.BLUE + os.uname()[4] + color.END
print(info)
print("=====================================")
print("with number of cpu: " + color.RED +
str(len(microcontroller.cpus)) + color.RED)
print()
</span></code></pre>
<p>To install CircuitPython firmware on Raspberry Pi, read the <b><a href="https://helloraspberrypi.blogspot.com/2021/01/circuitpython-on-raspberry-pi-pico.html">HERE</a></b>.</p>
<p><br /></p>
Erikhttp://www.blogger.com/profile/04983894331825656853noreply@blogger.com0tag:blogger.com,1999:blog-2462129950262077729.post-21654886084996056892021-09-25T08:05:00.000-07:002021-09-25T08:05:01.957-07:00Editor with split views feature, support Raspberry Pi - Kate <p><a href="https://kate-editor.org/" target="_blank">Kate</a> is a feature-packed text editor, lets you to edit and view many files at the same time, both in tabs and split views, and comes with a wide variety of plugins, including an embedded terminal that lets you launch console commands directly from Kate, powerful search and replace plugins, and a preview plugin that can show you what your MD, HTML and even SVG will look like.</p><p>To install Kate on Raspberry i:<br /><b>$ sudo apt install kate</b></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMkbH0VQzWvG2h4mk-Fq_phpxsFd0079Tf73DzVWcs5gKaz7ZwK1m83ebQ5GdFN8Z5IGaif_SOfPD_ZiOV5pmLe7Mpv7Wn10HSElw4XsVnzN8rWMJ20yDXclLLkVLJd2I8mSZdVoF60A43/s2000/kate_01.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1200" data-original-width="2000" height="384" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgMkbH0VQzWvG2h4mk-Fq_phpxsFd0079Tf73DzVWcs5gKaz7ZwK1m83ebQ5GdFN8Z5IGaif_SOfPD_ZiOV5pmLe7Mpv7Wn10HSElw4XsVnzN8rWMJ20yDXclLLkVLJd2I8mSZdVoF60A43/w640-h384/kate_01.jpg" width="640" /></a></div><br /><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLf0l4qvHtQE7gx2Gr4Pb3y-Vverr5zpr29eIZEc-IOzA4N7uWl7-xf0Ao3ogqPuPKXQhJ14amsIrJAG1WIqZGPv8PhgJSH7v5hbp3j8Lsv8d6zKyacWSu0Rt_gudxWPbC1z6YVzLvO9tY/s2000/kate_02.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1200" data-original-width="2000" height="384" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLf0l4qvHtQE7gx2Gr4Pb3y-Vverr5zpr29eIZEc-IOzA4N7uWl7-xf0Ao3ogqPuPKXQhJ14amsIrJAG1WIqZGPv8PhgJSH7v5hbp3j8Lsv8d6zKyacWSu0Rt_gudxWPbC1z6YVzLvO9tY/w640-h384/kate_02.jpg" width="640" /></a></div><br /><p><br /></p>rpiihttp://www.blogger.com/profile/11029985001257500904noreply@blogger.com0tag:blogger.com,1999:blog-2462129950262077729.post-48201636377778779142021-09-20T14:19:00.003-07:002022-05-08T08:01:47.107-07:00Download and Install openEuler on Raspberry Pi<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgR9AxFF0k9MzKIXXgwh2csz1l0tc6QlJKinfPvUvDFUvsCYLa9Ln54ulQp2DHvXXgTGRP8H43iUNnlyPvHSKzuQL2Vk-NWsUMPO8ouTs98RLQ-TnwPTHKOxQOkjpKSrz2IKRav7KlBouw/s1000/openEuler_Raspberry_Pi.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="754" data-original-width="1000" height="482" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgR9AxFF0k9MzKIXXgwh2csz1l0tc6QlJKinfPvUvDFUvsCYLa9Ln54ulQp2DHvXXgTGRP8H43iUNnlyPvHSKzuQL2Vk-NWsUMPO8ouTs98RLQ-TnwPTHKOxQOkjpKSrz2IKRav7KlBouw/w640-h482/openEuler_Raspberry_Pi.jpg" width="640" /></a>
</div>
<p>
This video show how to download, install and run openEuler on Raspberry Pi,
and switch language to English. Tested on Raspberry Pi 4B/4G with 7 inch mini
HDMI LCD. Chinese is set system language by default, this video also show how
to switch to English.
</p>
<center>
<iframe allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/vFn1mcv1faQ" title="YouTube video player" width="560"></iframe>
</center>
<p>
<u><b>Download openEuler image for Raspberry Pi<br /></b></u>(prepare on Raspberry Pi)
</p>
<p>
Visit
<a href="https://www.openeuler.org/en/" target="_blank">https://www.openeuler.org/en/</a>, scroll down and click on "use openEuler OS", choose Raspberry Pi.
</p>
<p>
In the new opened page, scroll down to How to download latest image, (<a href="https://gitee.com/openeuler/raspberrypi#how-to-download-latest-image" target="_blank">https://gitee.com/openeuler/raspberrypi#how-to-download-latest-image</a>).
</p>
<p>
Select the image to download, in my test: openEuler 20.03 LTS SP1 alpha4 (DDE
desktop and Chinese input method),
openEuler-20.03-LTS-SP1-DDE-raspi-aarch64-alpha4.img.xz.
</p>
<p>
Extract the downloaded file. Then we can write the extracted image on microSD
using Raspberry Pi Imager.
</p>
<p>Then you can boot-up Raspberry Pi with the microSD. </p>
<p>
<b><u>User and password:</u></b>
</p>
<p>
The image pre-set with System user/password:<br />-
root/openeuler <br />- pi/raspberry
</p>
<p>
DDE cannot log in with root account,
<b>you can login user pi using password "raspberry".</b>
</p>
<p><br /></p>
<p><i>FYI: the microSD I used in this test is 128G Samsung Evo Plus:</i></p>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDxx_IFIepkE8JYoQzGmHCZ6xVAwW3yVjvKCLcaL122UAzliOTBNpMgUdRd9_iGLIyn1e4uLaUrU4mddrtwVAeiJn1_lL7B01Cs8sJ_t7Wv3gNNX1ZWv1CDV3p1g04N4OiVDI5kHeZr-4/s600/openEuler_Raspberry_Pi_microSD.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="454" data-original-width="600" height="303" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDxx_IFIepkE8JYoQzGmHCZ6xVAwW3yVjvKCLcaL122UAzliOTBNpMgUdRd9_iGLIyn1e4uLaUrU4mddrtwVAeiJn1_lL7B01Cs8sJ_t7Wv3gNNX1ZWv1CDV3p1g04N4OiVDI5kHeZr-4/w400-h303/openEuler_Raspberry_Pi_microSD.jpg" width="400" /></a>
</div>
<br />
<p><br /></p>
<hr />
Related:<div>~ <a href="https://helloraspberrypi.blogspot.com/2021/09/install-openeuler-in-virtualbox-and.html" target="">Install openEuler in VirtualBox, and install Deepin Desktop Environment (DDE)</a></div><div><br />Updated@2022-05-08<br />~ <a href="https://helloraspberrypi.blogspot.com/2022/05/openeuler-2203-lts-ukui-desktop-run-on.html">OpenEuler 22.03 LTS (UKUI Desktop) run on Raspberry Pi 4</a><br /><br /><br /></div>Erikhttp://www.blogger.com/profile/04983894331825656853noreply@blogger.com0tag:blogger.com,1999:blog-2462129950262077729.post-52146192831659019602021-09-18T09:19:00.001-07:002021-09-20T14:29:13.780-07:00Install openEuler in VirtualBox, and install Deepin Desktop Environment (DDE)<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9GoCiC_PM9dOsWHxSPP-mRld1q_GMLxJMfnA38RJpjGCE2LxqP5-yJuan6YuhvycnzmmHEdMB-qMC4aDEJwEcjgAn9gMfEBDm7BXMi7m5fgKmTtlRPofo8zCQIxyTOdYp7SrrjYjx4xY/s1366/Screenshot+%252874%2529.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="768" data-original-width="1366" height="360" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9GoCiC_PM9dOsWHxSPP-mRld1q_GMLxJMfnA38RJpjGCE2LxqP5-yJuan6YuhvycnzmmHEdMB-qMC4aDEJwEcjgAn9gMfEBDm7BXMi7m5fgKmTtlRPofo8zCQIxyTOdYp7SrrjYjx4xY/w640-h360/Screenshot+%252874%2529.png" width="640" /></a>
</div>
<p>
<a href="https://www.openeuler.org/en/" target="_blank"><b>openEuler</b></a>
is an innovative platform nurtured by community collaboration. It aims to
build a unified and open OS that supports multiple processor architectures,
and to advance the hardware/software application ecosystem.
</p>
<div>
This video show how to install openEuler in VirtualBox 6.1/Windows 10.
</div>
<div><br /></div>
<center>
<iframe allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/8Y7L37jNonE" title="YouTube video player" width="560"></iframe>
</center>
<div><br /></div>
<div>
<div>
Visit
<a href="https://www.openeuler.org/en/download/" target="_blank">https://www.openeuler.org/en/download/</a>
to download ISO. It's openEuler-20.03-LTS-SP2-x86_64-dvd.iso in my case.
</div>
</div>
<div><br /></div>
<div>
It's very straightforward to install openEuler in VirtualBox. But
there are no desktop environment by default. Deepin Desktop Environment
(DDE) can be installed using dnf (a Linux software package management
tool).
</div>
<div><br /></div>
<div>
Most probably you cannot run dnf, fail with error [Could not resolve
host: repo.openeuler.org], as shown in the video.
</div>
<div><br /></div>
<div>To fix it:</div>
<div>
<div>edit /etc/sysconfig/network-scripts/ifcfg-enp0s3</div>
<div>set <b>ONBOOT=yes</b></div>
</div>
<div><br /></div>
<div>save and then reboot.</div>
<div><br /></div>
<div>Then install DDE with command:</div>
<pre style="border: 1px solid black;"><code><span style="color: black;">sudo dnf update
sudo dnf install dde
sudo systemctl set-default graphical.target
sudo reboot
</span></code></pre>
<div>
After the restart is complete, use the user created during the installation
process or the openeuler user to log in to the desktop.
</div>
<div><br /></div>
<div><i>dde cannot log in with root account.</i></div>
<div>
<i>
dde has built-in <b>openeuler </b>user, the password of this user is
<b>openeuler</b>.
</i>
</div>
<div><br /></div>
<div>
ref: <a href="https://docs.openeuler.org/en/docs/20.03_LTS_SP2/docs/desktop/install-DDE.html" target="_blank">https://docs.openeuler.org/en/docs/20.03_LTS_SP2/docs/desktop/install-DDE.html</a>
</div>
<div><br /></div>
<hr />
Related:
<div>~ <a href="https://helloraspberrypi.blogspot.com/2021/09/download-and-install-openeuler-on.html">Download and Install openEuler on Raspberry Pi</a></div>Erikhttp://www.blogger.com/profile/04983894331825656853noreply@blogger.com0tag:blogger.com,1999:blog-2462129950262077729.post-68783656481054766072021-08-25T11:41:00.006-07:002021-09-07T06:12:03.932-07:00Bi-direction BLE communication between Raspberry Pi/Python (with PyQt5 GUI) and ESP32/Arduino Nano RP2040 Connect<p>
<b
><u><i>Raspberry Pi/Python/bluepy + ESP32</i></u></b
>
</p>
<p>
With
<a
href="https://helloraspberrypi.blogspot.com/2021/07/install-bluepy-on-raspberry-pi-for.html"
>bluepy installed</a
>, this exercise implement BLE client side on Raspberry Pi using Python,
connect to ESP32 BLE uart server, send and receive data in between.
</p>
<div class="separator" style="clear: both; text-align: center;">
<a
href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPfDHTYU3X8CCw9Hh2QZYIldWdCrWIUDB1pOZ8sIvRnxNBQn1nRvWezrMH1dn4f0odr2ad1BRrIIsvTRRT68-A3R2r-cv0BvxbyoVHgTgjMgIhdfHPMryiQiqTr5lshGSYLEStiGgM3f4/s1000/pyqt5-bluepy_01.jpg"
style="margin-left: 1em; margin-right: 1em;"
><img
border="0"
data-original-height="754"
data-original-width="1000"
height="482"
src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPfDHTYU3X8CCw9Hh2QZYIldWdCrWIUDB1pOZ8sIvRnxNBQn1nRvWezrMH1dn4f0odr2ad1BRrIIsvTRRT68-A3R2r-cv0BvxbyoVHgTgjMgIhdfHPMryiQiqTr5lshGSYLEStiGgM3f4/w640-h482/pyqt5-bluepy_01.jpg"
width="640"
/></a>
</div>
<br />
<center>
<iframe
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen=""
frameborder="0"
height="315"
src="https://www.youtube.com/embed/9hgID5zewmM"
title="YouTube video player"
width="560"
></iframe>
</center>
<p>
<b><u>Prepare ESP32 BLE_uart</u></b>
</p>
<p>ESP32 side (NodeMCU ESP-32S) is programmed in Arduino framework. </p>
<p>
In Arduino IDE<br />- Open Examples > ESP32 BLE Arduino > BLE_uart in
Arduino IDE, and upload to ESP32 board.
</p>
<p>
It's a BLE setup as server, wait connection. Once connected, send data to
client repeatedly and display received data to Serial Monitor.
</p>
<p>
<b><u>Test with nRF Connect App </u></b>
</p>
<p>
To verify the function of ESP32 BLE_art on Android device, install <a
href="https://play.google.com/store/apps/details?id=no.nordicsemi.android.mcp"
target="_blank"
>nRF Connect for Mobile App</a
>
by Nordic Semiconductor ASA.
</p>
<p>
<b><u>Simple test Python code -</u></b>
</p>
<p>Automatically connect to BLE_uart, send and receive data repeatedly.</p>
<p> ex_bluepy_uart.py</p>
<pre
style="border: 1px solid black;"
><code><span style="color: black;">from bluepy import btle
import time
class MyDelegate(btle.DefaultDelegate):
def __init__(self):
btle.DefaultDelegate.__init__(self)
# ... initialise here
def handleNotification(self, cHandle, data):
#print("\n- handleNotification -\n")
print(data)
# ... perhaps check cHandle
# ... process 'data'
# Initialisation -------
p = btle.Peripheral("3c:71:bf:0d:dd:6a") #NodeMCU-32S
#p = btle.Peripheral("24:0a:c4:e8:0f:9a") #ESP32-DevKitC V4
# Setup to turn notifications on, e.g.
svc = p.getServiceByUUID("6E400001-B5A3-F393-E0A9-E50E24DCCA9E")
ch_Tx = svc.getCharacteristics("6E400002-B5A3-F393-E0A9-E50E24DCCA9E")[0]
ch_Rx = svc.getCharacteristics("6E400003-B5A3-F393-E0A9-E50E24DCCA9E")[0]
p.setDelegate( MyDelegate())
setup_data = b"\x01\00"
p.writeCharacteristic(ch_Rx.valHandle+1, setup_data)
lasttime = time.localtime()
while True:
"""
if p.waitForNotifications(1.0):
pass #continue
print("Waiting...")
"""
nowtime = time.localtime()
if(nowtime > lasttime):
lasttime = nowtime
stringtime = time.strftime("%H:%M:%S", nowtime)
btime = bytes(stringtime, 'utf-8')
try:
ch_Tx.write(btime, True)
except btle.BTLEException:
print("btle.BTLEException");
#print(stringtime)
#ch_Tx.write(b'wait...', True)
# Perhaps do something else here
</span></code></pre>
<b><u>Python code with PyQt5 GUI -</u></b>
<div>- Click "Start BLE" button to connect to BLE_uart.</div>
<div>
- Display received data on QPlainTextEdit, and send user entered data to
BLE
</div>
<div><br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a
href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiadLcgZcuI-RmPPi3QOD6udaYXxGslw8rVvDGul950G7jHg1BRLpLuTxcjOqS0DtdB_6mYtY8zREdrV9gOyse7q5f0Nx-Gnrq1GBQ1ujaHyq9ZfJTKILiP5EoeDg9T_3-MFOe9r_mPGBA/s2000/pyqt5_bluepy_thread_.jpg"
style="margin-left: 1em; margin-right: 1em;"
><img
border="0"
data-original-height="1200"
data-original-width="2000"
height="384"
src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiadLcgZcuI-RmPPi3QOD6udaYXxGslw8rVvDGul950G7jHg1BRLpLuTxcjOqS0DtdB_6mYtY8zREdrV9gOyse7q5f0Nx-Gnrq1GBQ1ujaHyq9ZfJTKILiP5EoeDg9T_3-MFOe9r_mPGBA/w640-h384/pyqt5_bluepy_thread_.jpg"
width="640"
/></a>
</div>
<br />
<div>
-
<a
href="https://helloraspberrypi.blogspot.com/2021/07/install-pyqt5-for-python3-on-raspberry.html"
>Install PyQt5 on raspberry Pi</a
>
</div>
<div><br /></div>
pyqt5_bluepy_thread_.py
<pre
style="border: 1px solid black;"
><code><span style="color: black;">import sys
import time
import requests
from PyQt5.QtCore import QObject, QRunnable, QThreadPool, QTimer, pyqtSignal, pyqtSlot
from PyQt5.QtWidgets import (
QApplication, QLabel, QMainWindow, QPlainTextEdit, QPushButton, QVBoxLayout, QWidget,
)
from bluepy import btle
class WorkerSignals(QObject):
signalMsg = pyqtSignal(str)
signalRes = pyqtSignal(str)
class MyDelegate(btle.DefaultDelegate):
def __init__(self, sgn):
btle.DefaultDelegate.__init__(self)
self.sgn = sgn
def handleNotification(self, cHandle, data):
try:
dataDecoded = data.decode()
self.sgn.signalRes.emit(dataDecoded)
except UnicodeError:
print("UnicodeError: ", data)
class WorkerBLE(QRunnable):
def __init__(self):
super().__init__()
self.signals = WorkerSignals()
self.rqsToSend = False
@pyqtSlot()
def run(self):
self.signals.signalMsg.emit("WorkerBLE start")
#---------------------------------------------
p = btle.Peripheral("3c:71:bf:0d:dd:6a")
p.setDelegate( MyDelegate(self.signals) )
svc = p.getServiceByUUID("6E400001-B5A3-F393-E0A9-E50E24DCCA9E")
self.ch_Tx = svc.getCharacteristics("6E400002-B5A3-F393-E0A9-E50E24DCCA9E")[0]
ch_Rx = svc.getCharacteristics("6E400003-B5A3-F393-E0A9-E50E24DCCA9E")[0]
setup_data = b"\x01\00"
p.writeCharacteristic(ch_Rx.valHandle+1, setup_data)
# BLE loop --------
while True:
"""
if p.waitForNotifications(1.0):
# handleNotification() was called
continue
print("Waiting...")
"""
p.waitForNotifications(1.0)
if self.rqsToSend:
self.rqsToSend = False
try:
self.ch_Tx.write(self.bytestosend, True)
except btle.BTLEException:
print("btle.BTLEException");
#---------------------------------------------hellohello
self.signals.signalMsg.emit("WorkerBLE end")
def toSendBLE(self, tosend):
self.bytestosend = bytes(tosend, 'utf-8')
self.rqsToSend = True
"""
try:
self.ch_Tx.write(bytestosend, True)
except BTLEException:
print("BTLEException");
"""
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
layout = QVBoxLayout()
buttonStartBLE = QPushButton("Start BLE")
buttonStartBLE.pressed.connect(self.startBLE)
self.console = QPlainTextEdit()
self.console.setReadOnly(True)
self.outconsole = QPlainTextEdit()
buttonSendBLE = QPushButton("Send message")
buttonSendBLE.pressed.connect(self.sendBLE)
layout.addWidget(buttonStartBLE)
layout.addWidget(self.console)
layout.addWidget(self.outconsole)
layout.addWidget(buttonSendBLE)
w = QWidget()
w.setLayout(layout)
self.setCentralWidget(w)
self.show()
self.threadpool = QThreadPool()
print(
"Multithreading with Maximum %d threads" % self.threadpool.maxThreadCount())
def startBLE(self):
self.workerBLE = WorkerBLE()
self.workerBLE.signals.signalMsg.connect(self.slotMsg)
self.workerBLE.signals.signalRes.connect(self.slotRes)
self.threadpool.start(self.workerBLE)
def sendBLE(self):
strToSend = self.outconsole.toPlainText()
self.workerBLE.toSendBLE(strToSend)
def slotMsg(self, msg):
print(msg)
def slotRes(self, res):
self.console.appendPlainText(res)
app = QApplication(sys.argv)
window = MainWindow()
app.exec()
</span></code></pre>
<div><br /></div>
<hr />
<b
><i><u> Raspberry Pi/Python/bluepy + Arduino Nano RP2040 Connect</u></i></b
><br />
<br />
<div>
Now, replace ESP32 with Arduino Nano RP2040 Connect, running following
code using ArduinoBLE library. Please note that you have to modify
Python code to match with Arduino Nano RP2040 Connect's MAC address.
</div>
<div><br /></div>
<center>
<iframe width="560" height="315" src="https://www.youtube.com/embed/-uZN2IjmnXE" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</center>
<div><br /></div>
BLE_peripheral_uart.ino
<pre style="border: 1px solid black;"><code><span style="color: black;">/*
* BLE_peripheral_uart:
* modifid from Examples > ArduinoBLE > Peripheral > CallbackLED
*
* Bi-direction BLE communication between Raspberry Pi/Python (with PyQt5 GUI)
* and ESP32/Arduino Naon RP2040 Connect
* http://helloraspberrypi.blogspot.com/2021/08/bi-direction-ble-communication-between.html
*
*/
#include <ArduinoBLE.h>
#define SERVICE_UUID "6E400001-B5A3-F393-E0A9-E50E24DCCA9E" // UART service UUID
#define CHARACTERISTIC_UUID_RX "6E400002-B5A3-F393-E0A9-E50E24DCCA9E"
#define CHARACTERISTIC_UUID_TX "6E400003-B5A3-F393-E0A9-E50E24DCCA9E"
//BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // create service
BLEService uartService(SERVICE_UUID); // create service
// create switch characteristic and allow remote device to read and write
//BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
BLEStringCharacteristic rxCharacteristic(CHARACTERISTIC_UUID_RX, BLEWrite, 30);
BLEStringCharacteristic txCharacteristic(CHARACTERISTIC_UUID_TX, BLENotify, 30);
// const int ledPin = LED_BUILTIN; // pin to use for the LED
void setup() {
Serial.begin(115200);
while (!Serial);
// pinMode(ledPin, OUTPUT); // use the LED pin as an output
// begin initialization
if (!BLE.begin()) {
Serial.println("starting BLE failed!");
while (1);
}
// set the local name peripheral advertises
BLE.setLocalName("BLE_peripheral_uart");
// set the UUID for the service this peripheral advertises
BLE.setAdvertisedService(uartService);
// add the characteristic to the service
uartService.addCharacteristic(rxCharacteristic);
uartService.addCharacteristic(txCharacteristic);
// add service
BLE.addService(uartService);
// assign event handlers for connected, disconnected to peripheral
BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler);
BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler);
// assign event handlers for characteristic
rxCharacteristic.setEventHandler(BLEWritten, rxCharacteristicWritten);
// set an initial value for the characteristic
rxCharacteristic.setValue("BLE_peripheral_uart");
// start advertising
BLE.advertise();
Serial.println(("Bluetooth device active, waiting for connections..."));
Serial.println(BLE.address());
}
void loop() {
// poll for BLE events
BLE.poll();
}
void blePeripheralConnectHandler(BLEDevice central) {
// central connected event handler
Serial.print("Connected event, central: ");
Serial.println(central.address());
}
void blePeripheralDisconnectHandler(BLEDevice central) {
// central disconnected event handler
Serial.print("Disconnected event, central: ");
Serial.println(central.address());
}
void rxCharacteristicWritten(BLEDevice central, BLECharacteristic characteristic) {
// central wrote new value to characteristic, update LED
Serial.print("Characteristic event, written: ");
Serial.println("len=" +
String(rxCharacteristic.valueLength()));
String valString = rxCharacteristic.value();
Serial.println(valString);
valString.toUpperCase();
Serial.println(valString);
txCharacteristic.setValue(valString);
}
</span></code></pre>
<br />
<br />
Erikhttp://www.blogger.com/profile/04983894331825656853noreply@blogger.com0tag:blogger.com,1999:blog-2462129950262077729.post-80644947405351013062021-08-18T07:41:00.008-07:002021-08-22T15:51:19.537-07:00ov7670/ov2640 + ST7789 (IPS Display) on Raspberry Pi Pico/CircuitPython 7.0.0 alpha 6<p>
This post show how to connect OV7670/OV2640 0.3-Megapixel Camera Module to
Raspberry Pi Pico (in CircuitPython 7.0.0 alpha 6), display on ST7789 SPI IPS
screen; running example ov2640_jpeg_sd_pico_st7789_2in.py.
</p>
<p>
<b><i><u>ov7670:</u></i></b>
</p>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicOg-Q2Ey9yd1u3K4esDlxAXKtIVD2a_KcOX3xPa2G6l_tn5C0SKX3BvzsVKL8P35R1Q3t4EVq564i-jeuPBjvwxHwDFYJaLocK8BZmnY02AN_LfP8GexGiVKRO0TDNcB1JlazcN7Gvcc/s1000/ov7670.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="754" data-original-width="1000" height="482" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicOg-Q2Ey9yd1u3K4esDlxAXKtIVD2a_KcOX3xPa2G6l_tn5C0SKX3BvzsVKL8P35R1Q3t4EVq564i-jeuPBjvwxHwDFYJaLocK8BZmnY02AN_LfP8GexGiVKRO0TDNcB1JlazcN7Gvcc/w640-h482/ov7670.jpg" width="640" /></a>
</div>
<br />It's library named adafruit_ov7670.mpy and example
named ov7670_displayio_pico_st7789_2in.py in CircuitPython Bundle
Libraries. I tried to run it on Pico with current stable CircuitPython
6.3.0. But fail with error of:
<div>
<br /><b><i>ImportError: cannot import name Colorspace</i></b><br />
<div><br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhX1jUYwx9Ay40JLbH9H-Lx7zRrWYwc1He8fOd-RDqUpCAoCdHwzyU89IfGko-beySXjJAeYeoRCmTy3V3foLLLCUj3Cd84maAsxke4mjoJTQ350BqE_h7QIMw92QFtDESWC3wKcY9UhbM/s2000/Colorspace.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1200" data-original-width="2000" height="384" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhX1jUYwx9Ay40JLbH9H-Lx7zRrWYwc1He8fOd-RDqUpCAoCdHwzyU89IfGko-beySXjJAeYeoRCmTy3V3foLLLCUj3Cd84maAsxke4mjoJTQ350BqE_h7QIMw92QFtDESWC3wKcY9UhbM/w640-h384/Colorspace.jpg" width="640" /></a>
</div>
<br />
<div>Then I tried on CircuitPython 7.0.0 alpha 6.</div>
<div><br /></div>
<div>
The connection between Pico and ov7670 camera module and st7789 SPI IPS
display follow the ov7670_displayio_pico_st7789_2in.py example. But I have
to add reset pin for display.
</div>
<div><br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBaBi8jq0C5guaJd21eRjnpEGIHBnTYI6nj2GEIWj5jvo0PorKRp4DNqA4PduwNLRErCkP4i34rqmvuqHDb3NohkYyvh3JO2FgteP3L6itPE3EsMO1ebTNBGgdDk5AX7CB-2crkKlwrqU/s2000/ov2640_jpeg_sd_pico_st7789_2in.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1200" data-original-width="2000" height="384" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBaBi8jq0C5guaJd21eRjnpEGIHBnTYI6nj2GEIWj5jvo0PorKRp4DNqA4PduwNLRErCkP4i34rqmvuqHDb3NohkYyvh3JO2FgteP3L6itPE3EsMO1ebTNBGgdDk5AX7CB-2crkKlwrqU/w640-h384/ov2640_jpeg_sd_pico_st7789_2in.jpg" width="640" /></a>
</div>
<br />
<div>
<b><u>Connection:</u></b>
</div>
</div>
<pre style="border: 1px solid black;"><code><span style="color: black;">Connection between Pico and ov7670 cam module
=============================================
+-----------+
3V3 |3V3 DGND| GND
GP9 |SCL SDA | GP8
GP7 |VS HS<span> </span>| GP21
GP11 |PLK XLK | GP20
GP19 |D7 D6 | GP18
GP17 |D5 D4 | GP16
GP15 |D3 D2 | GP14
GP13 |D1 D0 | GP12
GP10 |RET PWDN|
+-----------+
*SCL/SDA are I2C control pin, pull-up resistors are needed.
I use 2K ohm resistor for it.
Connection between Pico and ST7789 SPI IPS
==========================================
3V3 BLK
GP1 CS
GP0 DC
GP4 RES
GP3 SDA
GP2 SCL
3V3 VCC
GND GND</span></code></pre>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzkBYF06WkXBdfFZS7Y7jWl1SaeLoT5y6wor_zLUcPX3D-r3h7Sfm8SPRmWUP4HYU8XQ7ftWg8k-WhLD5vBok5ocv1AUnyjpjVrbSTBxJfEYbF9Gn-fE5A542Q4QgfkAiqZrLrzKP2SB0/s1800/pico_ov_bbxx_1800x1080.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1080" data-original-width="1800" height="384" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzkBYF06WkXBdfFZS7Y7jWl1SaeLoT5y6wor_zLUcPX3D-r3h7Sfm8SPRmWUP4HYU8XQ7ftWg8k-WhLD5vBok5ocv1AUnyjpjVrbSTBxJfEYbF9Gn-fE5A542Q4QgfkAiqZrLrzKP2SB0/w640-h384/pico_ov_bbxx_1800x1080.png" width="640" /></a><br />
</div>
Makesure Raspberry Pi Pico is installed with CircuitPython 7.0.0 alpha 6,
download the matched bundle libraries 7.x. Copy adafruit_st7789.mpy
and adafruit_ov7670.mpy from lib folder to Pico CIRCUITPY lib folder.
Modify ov7670_displayio_pico_st7789_2in.py from examples folder to add
reset pin to GP4, as shown in above screenshot.
<div><br /></div>
<div>remark:</div>
<div>
In my test, once the program ran and stopped, to re-run it, have to disconnect
and reconnect USB to Pico.
</div>
<div><br /></div>
<center>
<iframe allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/Ld3W9UmPRHc" title="YouTube video player" width="560"></iframe>
</center>
<br />
<hr /><b><i><u>
ov2640:
</u></i></b><div><br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggjMT0G_rc2u8cx_OeLUGkJVYyiTj6PdSKdb3MwOe2pDjM6e4YtELxW6jMkXb20Hfps_E0CE-Kkk23EzD4ugyxKZNuXMrkI7JX_koQ5omc7qCv88psZp_Q4Y8SCD5zFJQdsWhb4yAOdjw/s1000/Pico_oc2640_01.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="754" data-original-width="1000" height="482" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggjMT0G_rc2u8cx_OeLUGkJVYyiTj6PdSKdb3MwOe2pDjM6e4YtELxW6jMkXb20Hfps_E0CE-Kkk23EzD4ugyxKZNuXMrkI7JX_koQ5omc7qCv88psZp_Q4Y8SCD5zFJQdsWhb4yAOdjw/w640-h482/Pico_oc2640_01.jpg" width="640" /></a>
</div>
<br />
<div>
My ov2640 module have same pin assignment in ov7670, aligned to top with D0/D1
opened.
</div>
<div><br /></div>
<div><b><u>Connection:</u></b></div>
<pre style="border: 1px solid black;"><code><span style="color: black;">Connection between Pico and ov2640 cam module
=============================================
+-----------+
3V3 |3V3 GND<span> </span>| GND
GP9 |SIOC SIOD| GP8
GP7 |VSYNC HREF| GP21
GP11 |PCLK XCLK| GP20
GP19 |D9 D8<span> </span>| GP18
GP17 |D7 D6<span> </span>| GP16
GP15 |D5 D4<span> </span>| GP14
GP13 |D3 D2<span> </span>| GP12
GP10 |RESET PWDN|
|D1 D0<span> </span>|
+-----------+
</span></code></pre>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8duPv-PqeN_216Hq2x78kjk7r0Thc4-zOT6OPsr22-8z6efaov4JAhXVX6hUogY7UR_ez6fuDUp6AHc2lTHcxnM4JJ2BM-5ED141NuDiTcU3LTNilopk58lm-efarZOq_UJYHiuvrD6s/s1800/pico_ov2640_bbx_1800.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1080" data-original-width="1800" height="384" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8duPv-PqeN_216Hq2x78kjk7r0Thc4-zOT6OPsr22-8z6efaov4JAhXVX6hUogY7UR_ez6fuDUp6AHc2lTHcxnM4JJ2BM-5ED141NuDiTcU3LTNilopk58lm-efarZOq_UJYHiuvrD6s/w640-h384/pico_ov2640_bbx_1800.png" width="640" /></a>
</div>
<b><u>Library:</u></b>
<div>
Copy adafruit_ov2640.mpy and adafruit_st7789.mpy from CircuitPython bundle 7.x
lib to CIRCUITPY lib folder.
</div>
<div><br /></div>
<div><b><u>Example:</u></b></div>
<div><br /></div>
<div>
Locate and edit ov2640_displayio_pico_st7789_2in.py
from CircuitPython bundle 7.x examples, as shown in this video:
</div>
<div><br /></div>
<center>
<iframe allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/EM304pYqRYQ" title="YouTube video player" width="560"></iframe>
</center>
<div>
<div><br /></div>
</div>
Erikhttp://www.blogger.com/profile/04983894331825656853noreply@blogger.com0tag:blogger.com,1999:blog-2462129950262077729.post-48002883589665901232021-08-11T13:01:00.005-07:002021-08-18T08:08:23.324-07:00ST7789 SPI (2" 240x320/1.54" 240x240) IPS RGB Display, on Raspberry Pi Pico/CircuitPython<p>
Test 2" 240x320 and 1.54" 240x240 ST7789 SPI IPS RGB Display, on Raspberry Pi
Pico/CircuitPython.
</p>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtXrz_8B0_qYlFfU0ff1aBh-TkJny5OuK4cjtTjgKD21h2BAz7ef7QwWoeGNP0x-1vuCbYxifw3_N7BOXhmz53GP3rbb4n4D0VlQyG6zRBnG6JnKvtUEBJr1mipc3qPe0cmwJW1ZmSUk0/s1000/spiST7789_Pico.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="754" data-original-width="1000" height="482" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtXrz_8B0_qYlFfU0ff1aBh-TkJny5OuK4cjtTjgKD21h2BAz7ef7QwWoeGNP0x-1vuCbYxifw3_N7BOXhmz53GP3rbb4n4D0VlQyG6zRBnG6JnKvtUEBJr1mipc3qPe0cmwJW1ZmSUk0/w640-h482/spiST7789_Pico.jpg" width="640" /></a>
</div>
<br />
<center>
<iframe allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/pjHQnpqjyLs" title="YouTube video player" width="560"></iframe>
</center>
<p>
<u><b>Connection:</b></u>
</p>
<pre style="border: 1px solid black;"><code><span style="color: black;">3V3 - BLK
GP11 - CS
GP12 - DC
GP13 - RES
GP15 - SDA
GP14 - SCL
3V3 - VCC
GND - GND
</span></code></pre>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYzm7XjUuV6R3rZpMq38aICme_H3ljdlDLxXKGwL45T5nH_9ZIy0nJXu1NWgbaUxw2wk1O8zj-S6RxTppUw6oJbE6CHrkVhMp1Fuf7zJg4bEwtyqERHQBju7ebKnGi9YZBwyOD0SO3_ns/s1900/Pico_spiST7789_connection.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1300" data-original-width="1900" height="438" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYzm7XjUuV6R3rZpMq38aICme_H3ljdlDLxXKGwL45T5nH_9ZIy0nJXu1NWgbaUxw2wk1O8zj-S6RxTppUw6oJbE6CHrkVhMp1Fuf7zJg4bEwtyqERHQBju7ebKnGi9YZBwyOD0SO3_ns/w640-h438/Pico_spiST7789_connection.png" width="640" /></a>
</div>
<br /><u><b>Prepare Libraries:</b></u>
<div><br /></div>
<div>
<div>
Visit
<a href="https://circuitpython.org/libraries" target="_blank">https://circuitpython.org/libraries</a>, download the appropriate bundle for your version of CircuitPython.
</div>
<div><br /></div>
<div>
Unzip the file, copy adafruit_st7789.mpy, adafruit_display_text and
adafruit_display_shapes folder to the lib folder on your CIRCUITPY drive.
</div>
<div><br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlfDbO1XvAMXa30hu8Ag4vFs6segtRY6L4nX8p6SEqDcqrB0lSCS5Y3arZgbnEvY97HVLSKUNAd4gOwMxG_3wYfo8s92Lm_eSUmppD-PY1-Fd-KTC9QiGS2IswpkI68nNgS6I4OkLwCFc/s2000/libraries.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1200" data-original-width="2000" height="384" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjlfDbO1XvAMXa30hu8Ag4vFs6segtRY6L4nX8p6SEqDcqrB0lSCS5Y3arZgbnEvY97HVLSKUNAd4gOwMxG_3wYfo8s92Lm_eSUmppD-PY1-Fd-KTC9QiGS2IswpkI68nNgS6I4OkLwCFc/w640-h384/libraries.jpg" width="640" /></a>
</div>
<br />
<div>
<b><u>Examples code for 2" 240x320 ST7789 SPI IPS RGB Display :</u></b>
</div>
<div><br /></div>
cpyPico_spiST7789_320.py
<pre style="border: 1px solid black;"><code><span style="color: black;">"""
Example of CircuitPython/RaspberryPi Pico
to display on 2.0" IPS 240x320 (RGB) screen
with ST7789 driver via SPI interface.
Connection between Pico and
the IPS screen, with ST7789 SPI interface.
3V3 - BLK (backlight, always on)
GP11 - CS
GP12 - DC
GP13 - RES
GP15 - SDA
GP14 - SCL
3V3 - VCC
GND - GND
"""
import os
import board
import time
import terminalio
import displayio
import busio
from adafruit_display_text import label
#from adafruit_st7789 import ST7789
import adafruit_st7789
print("==============================")
print(os.uname())
print("Hello Raspberry Pi Pico/CircuitPython ST7789 SPI IPS Display")
print(adafruit_st7789.__name__ + " version: " + adafruit_st7789.__version__)
print()
# Release any resources currently in use for the displays
displayio.release_displays()
tft_cs = board.GP11
tft_dc = board.GP12
tft_res = board.GP13
spi_mosi = board.GP15
spi_clk = board.GP14
"""
classbusio.SPI(clock: microcontroller.Pin,
MOSI: Optional[microcontroller.Pin] = None,
MISO: Optional[microcontroller.Pin] = None)
"""
spi = busio.SPI(spi_clk, MOSI=spi_mosi)
display_bus = displayio.FourWire(
spi, command=tft_dc, chip_select=tft_cs, reset=tft_res
)
display = adafruit_st7789.ST7789(display_bus,
width=240, height=320)
# Make the display context
splash = displayio.Group(max_size=10)
display.show(splash)
color_bitmap = displayio.Bitmap(135, 240, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0x00FF00
bg_sprite = displayio.TileGrid(color_bitmap,
pixel_shader=color_palette, x=0, y=0)
splash.append(bg_sprite)
# Draw a smaller inner rectangle
inner_bitmap = displayio.Bitmap(133, 238, 1)
inner_palette = displayio.Palette(1)
inner_palette[0] = 0x0000FF
inner_sprite = displayio.TileGrid(inner_bitmap,
pixel_shader=inner_palette, x=1, y=1)
splash.append(inner_sprite)
# Draw a label
text_group1 = displayio.Group(max_size=10, scale=2, x=20, y=40)
text1 = "RPi Pico"
text_area1 = label.Label(terminalio.FONT, text=text1, color=0xFF0000)
text_group1.append(text_area1) # Subgroup for text scaling
# Draw a label
text_group2 = displayio.Group(max_size=10, scale=1, x=20, y=60)
text2 = "CircuitPython"
text_area2 = label.Label(terminalio.FONT, text=text2, color=0xFFFFFF)
text_group2.append(text_area2) # Subgroup for text scaling
# Draw a label
text_group3 = displayio.Group(max_size=10, scale=1, x=20, y=100)
text3 = adafruit_st7789.__name__
text_area3 = label.Label(terminalio.FONT, text=text3, color=0x0000000)
text_group3.append(text_area3) # Subgroup for text scaling
# Draw a label
text_group4 = displayio.Group(max_size=10, scale=2, x=20, y=120)
text4 = adafruit_st7789.__version__
text_area4 = label.Label(terminalio.FONT, text=text4, color=0x000000)
text_group4.append(text_area4) # Subgroup for text scaling
splash.append(text_group1)
splash.append(text_group2)
splash.append(text_group3)
splash.append(text_group4)
time.sleep(3.0)
rot = 0
while True:
time.sleep(5.0)
rot = rot + 90
if (rot>=360):
rot =0
display.rotation = rot
</span></code></pre>
<br />
cpyPico_spiST7789_bitmap_320.py
<pre style="border: 1px solid black;"><code><span style="color: black;">"""
Example of CircuitPython/Raspberry Pi Pico
to display on 2.0" IPS 240x320 (RGB) screen
with ST7789 driver via SPI interface.
Connection between Pico and
the IPS screen, with ST7789 SPI interface.
3V3 - BLK (backlight, always on)
GP11 - CS
GP12 - DC
GP13 - RES
GP15 - SDA
GP14 - SCL
3V3 - VCC
GND - GND
"""
import os
import board
import time
import terminalio
import displayio
import busio
from adafruit_display_text import label
import adafruit_st7789
print("==============================")
print(os.uname())
print("Hello Raspberry Pi Pico/CircuitPython ST7789 SPI IPS Display")
print(adafruit_st7789.__name__ + " version: " + adafruit_st7789.__version__)
print()
# Release any resources currently in use for the displays
displayio.release_displays()
tft_cs = board.GP11
tft_dc = board.GP12
tft_res = board.GP13
spi_mosi = board.GP15
spi_clk = board.GP14
"""
classbusio.SPI(clock: microcontroller.Pin,
MOSI: Optional[microcontroller.Pin] = None,
MISO: Optional[microcontroller.Pin] = None)
"""
spi = busio.SPI(spi_clk, MOSI=spi_mosi)
display_bus = displayio.FourWire(
spi, command=tft_dc, chip_select=tft_cs, reset=tft_res
)
display = adafruit_st7789.ST7789(display_bus,
width=240, height=320)
display.rotation = 270
group = displayio.Group(max_size=10)
display.show(group)
bitmap_width = 320
bitmap_height = 240
bitmap = displayio.Bitmap(bitmap_width, bitmap_height, bitmap_height)
palette = displayio.Palette(bitmap_height)
for p in range(bitmap_height):
palette[p] = (0x010000*p) + (0x0100*p) + p
for y in range(bitmap_height):
for x in range(bitmap_width):
bitmap[x,y] = y
tileGrid = displayio.TileGrid(bitmap, pixel_shader=palette, x=0, y=0)
group.append(tileGrid)
time.sleep(3.0)
while True:
for p in range(bitmap_height):
palette[p] = p
time.sleep(3.0)
for p in range(bitmap_height):
palette[p] = 0x0100 * p
time.sleep(3.0)
for p in range(bitmap_height):
palette[p] = 0x010000 * p
time.sleep(3.0)
</span></code></pre>
<br />
cpyPico_spiST7789_shape_320.py
<pre style="border: 1px solid black;"><code><span style="color: black;">"""
Example of CircuitPython/Raspberry Pi Pico
to display on 2.0" IPS 240x320 (RGB) screen
with ST7789 driver via SPI interface.
modify example from:
https://circuitpython.readthedocs.io/projects/display-shapes/en/latest/index.html
Connection between Pico and
the IPS screen, with ST7789 SPI interface.
3V3 - BLK (backlight, always on)
GP11 - CS
GP12 - DC
GP13 - RES
GP15 - SDA
GP14 - SCL
3V3 - VCC
GND - GND
"""
import os
import board
import time
import terminalio
import displayio
import busio
import adafruit_st7789
from adafruit_display_shapes.rect import Rect
from adafruit_display_shapes.circle import Circle
from adafruit_display_shapes.roundrect import RoundRect
from adafruit_display_shapes.triangle import Triangle
print("==============================")
print(os.uname())
print("Hello Raspberry Pi Pico/CircuitPython ST7789 SPI IPS Display")
print(adafruit_st7789.__name__ + " version: " + adafruit_st7789.__version__)
print()
# Release any resources currently in use for the displays
displayio.release_displays()
tft_cs = board.GP11
tft_dc = board.GP12
tft_res = board.GP13
spi_mosi = board.GP15
spi_clk = board.GP14
"""
classbusio.SPI(clock: microcontroller.Pin,
MOSI: Optional[microcontroller.Pin] = None,
MISO: Optional[microcontroller.Pin] = None)
"""
spi = busio.SPI(spi_clk, MOSI=spi_mosi)
display_bus = displayio.FourWire(
spi, command=tft_dc, chip_select=tft_cs, reset=tft_res
)
display = adafruit_st7789.ST7789(display_bus,
width=240, height=320)
display.rotation = 270
splash = displayio.Group()
display.show(splash)
color_bitmap = displayio.Bitmap(320, 240, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0xFFFFFF
bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
splash.append(bg_sprite)
triangle = Triangle(170, 50, 120, 140, 210, 160, fill=0x00FF00, outline=0xFF00FF)
splash.append(triangle)
rect = Rect(80, 20, 41, 41, fill=0x0)
splash.append(rect)
circle = Circle(100, 100, 20, fill=0x00FF00, outline=0xFF00FF)
splash.append(circle)
rect2 = Rect(50, 100, 61, 81, outline=0x0, stroke=3)
splash.append(rect2)
roundrect = RoundRect(10, 10, 61, 81, 10, fill=0x0, outline=0xFF00FF, stroke=6)
splash.append(roundrect)
while True:
pass
</span></code></pre>
<br />
<div>
<b><u>Examples code for 1.54" 240x240 ST7789 SPI IPS RGB Display :</u></b>
</div>
<div>
<b><u><br /></u></b>
</div>
<div><br /></div>
cpyPico_spiST7789_240.py
<pre style="border: 1px solid black;"><code><span style="color: black;">"""
Example of CircuitPython/RaspberryPi Pico
to display on 2.0" IPS 240x320 (RGB) screen
with ST7789 driver via SPI interface.
Connection between Pico and
the IPS screen, with ST7789 SPI interface.
3V3 - BLK (backlight, always on)
GP11 - CS
GP12 - DC
GP13 - RES
GP15 - SDA
GP14 - SCL
3V3 - VCC
GND - GND
"""
import os
import board
import time
import terminalio
import displayio
import busio
from adafruit_display_text import label
#from adafruit_st7789 import ST7789
import adafruit_st7789
print("==============================")
print(os.uname())
print("Hello Raspberry Pi Pico/CircuitPython ST7789 SPI IPS Display")
print(adafruit_st7789.__name__ + " version: " + adafruit_st7789.__version__)
print()
# Release any resources currently in use for the displays
displayio.release_displays()
tft_cs = board.GP11
tft_dc = board.GP12
tft_res = board.GP13
spi_mosi = board.GP15
spi_clk = board.GP14
"""
classbusio.SPI(clock: microcontroller.Pin,
MOSI: Optional[microcontroller.Pin] = None,
MISO: Optional[microcontroller.Pin] = None)
"""
spi = busio.SPI(spi_clk, MOSI=spi_mosi)
display_bus = displayio.FourWire(
spi, command=tft_dc, chip_select=tft_cs, reset=tft_res
)
display = adafruit_st7789.ST7789(display_bus,
width=240, height=240, rowstart=80)
# Make the display context
splash = displayio.Group(max_size=10)
display.show(splash)
color_bitmap = displayio.Bitmap(135, 240, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0x00FF00
bg_sprite = displayio.TileGrid(color_bitmap,
pixel_shader=color_palette, x=0, y=0)
splash.append(bg_sprite)
# Draw a smaller inner rectangle
inner_bitmap = displayio.Bitmap(133, 238, 1)
inner_palette = displayio.Palette(1)
inner_palette[0] = 0x0000FF
inner_sprite = displayio.TileGrid(inner_bitmap,
pixel_shader=inner_palette, x=1, y=1)
splash.append(inner_sprite)
# Draw a label
text_group1 = displayio.Group(max_size=10, scale=2, x=20, y=40)
text1 = "RPi Pico"
text_area1 = label.Label(terminalio.FONT, text=text1, color=0xFF0000)
text_group1.append(text_area1) # Subgroup for text scaling
# Draw a label
text_group2 = displayio.Group(max_size=10, scale=1, x=20, y=60)
text2 = "CircuitPython"
text_area2 = label.Label(terminalio.FONT, text=text2, color=0xFFFFFF)
text_group2.append(text_area2) # Subgroup for text scaling
# Draw a label
text_group3 = displayio.Group(max_size=10, scale=1, x=20, y=100)
text3 = adafruit_st7789.__name__
text_area3 = label.Label(terminalio.FONT, text=text3, color=0x0000000)
text_group3.append(text_area3) # Subgroup for text scaling
# Draw a label
text_group4 = displayio.Group(max_size=10, scale=2, x=20, y=120)
text4 = adafruit_st7789.__version__
text_area4 = label.Label(terminalio.FONT, text=text4, color=0x000000)
text_group4.append(text_area4) # Subgroup for text scaling
splash.append(text_group1)
splash.append(text_group2)
splash.append(text_group3)
splash.append(text_group4)
time.sleep(3.0)
rot = 0
while True:
time.sleep(5.0)
rot = rot + 90
if (rot>=360):
rot =0
display.rotation = rot
</span></code></pre>
<br />
cpyPico_spiST7789_bitmap_240.py
<pre style="border: 1px solid black;"><code><span style="color: black;">"""
Example of CircuitPython/Raspberry Pi Pico
to display on 2.0" IPS 240x320 (RGB) screen
with ST7789 driver via SPI interface.
Connection between Pico and
the IPS screen, with ST7789 SPI interface.
3V3 - BLK (backlight, always on)
GP11 - CS
GP12 - DC
GP13 - RES
GP15 - SDA
GP14 - SCL
3V3 - VCC
GND - GND
"""
import os
import board
import time
import terminalio
import displayio
import busio
from adafruit_display_text import label
import adafruit_st7789
print("==============================")
print(os.uname())
print("Hello Raspberry Pi Pico/CircuitPython ST7789 SPI IPS Display")
print(adafruit_st7789.__name__ + " version: " + adafruit_st7789.__version__)
print()
# Release any resources currently in use for the displays
displayio.release_displays()
tft_cs = board.GP11
tft_dc = board.GP12
tft_res = board.GP13
spi_mosi = board.GP15
spi_clk = board.GP14
"""
classbusio.SPI(clock: microcontroller.Pin,
MOSI: Optional[microcontroller.Pin] = None,
MISO: Optional[microcontroller.Pin] = None)
"""
spi = busio.SPI(spi_clk, MOSI=spi_mosi)
display_bus = displayio.FourWire(
spi, command=tft_dc, chip_select=tft_cs, reset=tft_res
)
display = adafruit_st7789.ST7789(display_bus,
width=240, height=240, rowstart=80)
display.rotation = 270
group = displayio.Group(max_size=10)
display.show(group)
bitmap_width = 240
bitmap_height = 240
bitmap = displayio.Bitmap(bitmap_width, bitmap_height, bitmap_height)
palette = displayio.Palette(bitmap_height)
for p in range(bitmap_height):
palette[p] = (0x010000*p) + (0x0100*p) + p
for y in range(bitmap_height):
for x in range(bitmap_width):
bitmap[x,y] = y
tileGrid = displayio.TileGrid(bitmap, pixel_shader=palette, x=0, y=0)
group.append(tileGrid)
time.sleep(3.0)
while True:
for p in range(bitmap_height):
palette[p] = p
time.sleep(3.0)
for p in range(bitmap_height):
palette[p] = 0x0100 * p
time.sleep(3.0)
for p in range(bitmap_height):
palette[p] = 0x010000 * p
time.sleep(3.0)
</span></code></pre>
<br />
cpyPico_spiST7789_shape_240.py
<pre style="border: 1px solid black;"><code><span style="color: black;">"""
Example of CircuitPython/Raspberry Pi Pico
to display on 2.0" IPS 240x320 (RGB) screen
with ST7789 driver via SPI interface.
modify example from:
https://circuitpython.readthedocs.io/projects/display-shapes/en/latest/index.html
Connection between Pico and
the IPS screen, with ST7789 SPI interface.
3V3 - BLK (backlight, always on)
GP11 - CS
GP12 - DC
GP13 - RES
GP15 - SDA
GP14 - SCL
3V3 - VCC
GND - GND
"""
import os
import board
import time
import terminalio
import displayio
import busio
import adafruit_st7789
from adafruit_display_shapes.rect import Rect
from adafruit_display_shapes.circle import Circle
from adafruit_display_shapes.roundrect import RoundRect
from adafruit_display_shapes.triangle import Triangle
print("==============================")
print(os.uname())
print("Hello Raspberry Pi Pico/CircuitPython ST7789 SPI IPS Display")
print(adafruit_st7789.__name__ + " version: " + adafruit_st7789.__version__)
print()
# Release any resources currently in use for the displays
displayio.release_displays()
tft_cs = board.GP11
tft_dc = board.GP12
tft_res = board.GP13
spi_mosi = board.GP15
spi_clk = board.GP14
"""
classbusio.SPI(clock: microcontroller.Pin,
MOSI: Optional[microcontroller.Pin] = None,
MISO: Optional[microcontroller.Pin] = None)
"""
spi = busio.SPI(spi_clk, MOSI=spi_mosi)
display_bus = displayio.FourWire(
spi, command=tft_dc, chip_select=tft_cs, reset=tft_res
)
display = adafruit_st7789.ST7789(display_bus,
width=240, height=240, rowstart=80)
display.rotation = 270
splash = displayio.Group()
display.show(splash)
color_bitmap = displayio.Bitmap(240, 240, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0xFFFFFF
bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
splash.append(bg_sprite)
triangle = Triangle(170, 50, 120, 140, 210, 160, fill=0x00FF00, outline=0xFF00FF)
splash.append(triangle)
rect = Rect(80, 20, 41, 41, fill=0x0)
splash.append(rect)
circle = Circle(100, 100, 20, fill=0x00FF00, outline=0xFF00FF)
splash.append(circle)
rect2 = Rect(50, 100, 61, 81, outline=0x0, stroke=3)
splash.append(rect2)
roundrect = RoundRect(10, 10, 61, 81, 10, fill=0x0, outline=0xFF00FF, stroke=6)
splash.append(roundrect)
while True:
pass
</span></code></pre>
<div><br /></div>
</div>
<hr />
Related:
<div>
~ <a href="https://helloraspberrypi.blogspot.com/2021/01/raspberry-pi-picocircuitpython-st7789.html">Raspberry Pi Pico/CircuitPython + ST7789 SPI IPS LCD</a>
</div>
<div><br /></div><div>Next:</div><div>~ <a href="https://helloraspberrypi.blogspot.com/2021/08/ov7670-camera-st7789-ips-display-on.html">ov7670 (camera) + ST7789 (IPS Display) on Raspberry Pi Pico/CircuitPython 7.0.0 alpha 6</a></div><div><br /></div>
Erikhttp://www.blogger.com/profile/04983894331825656853noreply@blogger.com0tag:blogger.com,1999:blog-2462129950262077729.post-89235122302897644442021-07-15T08:41:00.003-07:002021-07-15T08:41:44.596-07:00Install PyQt5 for Python3 on Raspberry Pi OS<p>
To install PyQt5 on Raspberry Pi OS, for Python3, enter the command:
</p>
<pre style="border: 1px solid black;"><code><span style="color: black;">$ sudo apt install python3-pyqt5
</span></code></pre>
<div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLoldkwPh8fAvPXbQsy3ATtCpJk0QOLM1jLsc6T9HvmV4tVrhIHq812NGqFccPKqHMhGbXXD58YtdlpBzPpj16iUbVHKGdHmqnXQwhPyJNzHk7zKQeqwYcms6swHRY2r8O1RU0gufc4Z0/s1156/install+pyqt5.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1156" data-original-width="970" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLoldkwPh8fAvPXbQsy3ATtCpJk0QOLM1jLsc6T9HvmV4tVrhIHq812NGqFccPKqHMhGbXXD58YtdlpBzPpj16iUbVHKGdHmqnXQwhPyJNzHk7zKQeqwYcms6swHRY2r8O1RU0gufc4Z0/w538-h640/install+pyqt5.jpg" width="538" /></a>
</div>
<p>Currently, it's 5.11.3.</p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2hb5LO_Fq4wJdwfTQFZEgYTviBhi6llgNxi9ophPJkv775Zi8ShV0HVWK-ym3FqZbTsqMp652Dz4DRh41lEiZ2gx9JQMGopkCx_AevHLY8MEAErm_KkeKtREvK6rlF3aeCSB6AM-3lsA/s800/pyqt5_4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="480" data-original-width="800" height="384" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2hb5LO_Fq4wJdwfTQFZEgYTviBhi6llgNxi9ophPJkv775Zi8ShV0HVWK-ym3FqZbTsqMp652Dz4DRh41lEiZ2gx9JQMGopkCx_AevHLY8MEAErm_KkeKtREvK6rlF3aeCSB6AM-3lsA/w640-h384/pyqt5_4.jpg" width="640" /></a></div><br /><p><br /></p>
Erikhttp://www.blogger.com/profile/04983894331825656853noreply@blogger.com0tag:blogger.com,1999:blog-2462129950262077729.post-72200756799418544572021-07-15T06:32:00.001-07:002021-07-15T06:32:19.555-07:00Raspberry Pi: change screen orientationTo rotate screen in Raspberry Pi OS:
<div><br /></div>
<div>Click on MENU -> Preferences -> Screen Configuration</div>
<div>RIGHT Click on the monitor > Orientation -> Select direction</div>
<div><br /></div>
<center>
<iframe allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/H0_KjlhQNmY" title="YouTube video player" width="560"></iframe>
</center>
<div><br />Tested on <a href="https://helloraspberrypi.blogspot.com/2020/11/setup-4-inch-hdmi-display-c-on.html">4 inch HDMI IPS Touch Display</a>. Without installing custom
driver, the screen will be in vertical (portrait).
</div>
Erikhttp://www.blogger.com/profile/04983894331825656853noreply@blogger.com0tag:blogger.com,1999:blog-2462129950262077729.post-66601754758683219822021-07-13T02:24:00.008-07:002021-08-25T11:44:08.519-07:00Install bluepy on Raspberry Pi, for Python3, and examples.<p>
<b><a href="https://github.com/IanHarvey/bluepy" target="_blank">bluepy</a></b>
is a Python interface to Bluetooth LE on Linux.<br /><br />To install
bluepy on Raspberry Pi for Python3, enter the command:
</p>
<pre style="border: 1px solid black;"><code><span style="color: black;">$ sudo apt-get install python3-pip libglib2.0-dev
$ sudo pip3 install bluepy
</span></code></pre>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOrZhaKNszgJubCa4hpiJCU3dsLopobw0BReu_HpKbhyuxNyhBuvHgQ9h4c81OB6fYbAfuJow2zdjk8q9i3oO7DH8aY5VB1pVymY4iCb_SxGLg-ezCn2bscKR5VKjgbkh1qbuYKEJA_98/s1800/intall+bluepy.png" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1080" data-original-width="1800" height="384" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOrZhaKNszgJubCa4hpiJCU3dsLopobw0BReu_HpKbhyuxNyhBuvHgQ9h4c81OB6fYbAfuJow2zdjk8q9i3oO7DH8aY5VB1pVymY4iCb_SxGLg-ezCn2bscKR5VKjgbkh1qbuYKEJA_98/w640-h384/intall+bluepy.png" width="640" /></a>
</div>
<br />
<div>ref:</div>
<div>
~
<a href="http://ianharvey.github.io/bluepy-doc/index.html" target="_blank">bluepy documentation</a>
</div>
<div><br /></div>
<hr />
<b> bluepy examples: </b>
<div><br /></div>
<div>
There are two examples in bluepy, scanner and notification. Here how I modify
it for Python3 working on Raspberry Pi, work with ESP32 BLE_uart example.
</div>
<div><br /></div>
<center>
<iframe allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen="" frameborder="0" height="315" src="https://www.youtube.com/embed/yOaW5razdM8" title="YouTube video player" width="560"></iframe>
</center>
<div><br /></div>
scanner.py
<pre style="border: 1px solid black;"><code><span style="color: black;">from bluepy.btle import Scanner, DefaultDelegate
class ScanDelegate(DefaultDelegate):
def __init__(self):
DefaultDelegate.__init__(self)
def handleDiscovery(self, dev, isNewDev, isNewData):
if isNewDev:
print("Discovered device", dev.addr)
elif isNewData:
print("Received new data from", dev.addr)
scanner = Scanner().withDelegate(ScanDelegate())
devices = scanner.scan(10.0)
for dev in devices:
print("Device %s (%s), RSSI=%d dB" % (dev.addr, dev.addrType, dev.rssi))
for (adtype, desc, value) in dev.getScanData():
print(" %s = %s" % (desc, value))
</span></code></pre>
<div><br /></div>
notification.py
<pre style="border: 1px solid black;"><code><span style="color: black;">from bluepy import btle
class MyDelegate(btle.DefaultDelegate):
def __init__(self):
btle.DefaultDelegate.__init__(self)
# ... initialise here
def handleNotification(self, cHandle, data):
print("\n- handleNotification -\n")
print(data)
# ... perhaps check cHandle
# ... process 'data'
# Initialisation -------
p = btle.Peripheral("3c:71:bf:0d:dd:6a")
p.setDelegate( MyDelegate() )
# Setup to turn notifications on, e.g.
svc = p.getServiceByUUID("6E400001-B5A3-F393-E0A9-E50E24DCCA9E")
ch = svc.getCharacteristics("6E400003-B5A3-F393-E0A9-E50E24DCCA9E")[0]
# ch.write( setup_data )
setup_data = b"\x01\00"
p.writeCharacteristic(ch.valHandle+1, setup_data)
# Main loop --------
while True:
if p.waitForNotifications(1.0):
# handleNotification() was called
continue
print("Waiting...")
# Perhaps do something else here
</span></code></pre>
<br />
<hr />
Next:
<div>~ <a href="https://helloraspberrypi.blogspot.com/2021/08/bi-direction-ble-communication-between.html">Bi-direction BLE communication between Raspberry Pi/Python (with PyQt5 GUI) and ESP32</a></div><div><br /></div>Erikhttp://www.blogger.com/profile/04983894331825656853noreply@blogger.com0