Raspberry BASIC

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - John Spikowski

Pages: [1] 2 3 ... 15
1
General Discussion / Re: ESP32 MicroPython
« on: March 21, 2021, 12:49:05 am »
I was able to get my NeoPixel stick working under MicroPython on my ESP32-PICO-D4 controller.

The picture doesn't do the color presentation any justice. Looks great live.

I can see this being used to create outdoor billboards. A string of NeoPixels to decorate a Christmas tree is another idea.

Code: Python
  1. import machine, neopixel
  2. n = 8
  3. p = 5
  4. np = neopixel.NeoPixel(machine.Pin(p), n)
  5. np[0] = (255, 0, 0)
  6. np[1] = (0, 255, 0)
  7. np[2] = (0, 0, 255)
  8. np[3] = (128, 0, 0)
  9. np[4] = (0, 128, 0)
  10. np[5] = (0, 0, 128)
  11. np[6] = (125, 204, 223)
  12. np[7] = (255, 0, 153)
  13. np.write()
  14.  

This example I converted from CircuitPython displays a rainbow effect.

NeoPixel Rainbow video clip. I hide the stick to cut down on the glare.  8)

Code: Python
  1. # MicroPython demo - NeoPixel
  2. import time
  3.  
  4. import machine
  5. import neopixel
  6.  
  7. pixel_pin = machine.Pin(5)
  8. num_pixels = 8
  9.  
  10. pixels = neopixel.NeoPixel(pixel_pin, num_pixels)
  11.  
  12.  
  13. def wheel(pos):
  14.     # Input a value 0 to 255 to get a color value.
  15.     # The colours are a transition r - g - b - back to r.
  16.     if pos < 0 or pos > 255:
  17.         return (0, 0, 0)
  18.     if pos < 85:
  19.         return (255 - pos * 3, pos * 3, 0)
  20.     if pos < 170:
  21.         pos -= 85
  22.         return (0, 255 - pos * 3, pos * 3)
  23.     pos -= 170
  24.     return (pos * 3, 0, 255 - pos * 3)
  25.  
  26.  
  27. def rainbow_cycle(wait):
  28.     for j in range(255):
  29.         for i in range(num_pixels):
  30.             rc_index = (i * 256 // num_pixels) + j
  31.             pixels[i] = wheel(rc_index & 255)
  32.         pixels.write()
  33.         time.sleep(wait)
  34.  
  35.  
  36. while True:
  37.     rainbow_cycle(0)  # Increase the number to slow down the rainbow
  38.  



2
General Discussion / Re: ESP32 MicroPython
« on: March 18, 2021, 07:26:12 pm »
I tried to install the ESP-IDF tools on my RPi 4B running Ubuntu 64 bit.

This sucks!


jrs@RPi-Dev:~/esp/esp-idf$ ./install.sh
Detecting the Python interpreter
Checking "python" ...
/home/jrs/esp/esp-idf/tools/detect_python.sh: line 16: python: command not found
Checking "python3" ...
Python 3.8.6
"python3" has been detected
Installing ESP-IDF tools
Installing tools: xtensa-esp32-elf, xtensa-esp32s2-elf, xtensa-esp32s3-elf, riscv32-esp-elf, esp32ulp-elf, esp32s2ulp-elf, openocd-esp32
ERROR: tool xtensa-esp32-elf does not have versions compatible with platform linux-arm64
jrs@RPi-Dev:~/esp/esp-idf$



On a positive note I was able to install the ESP32 development tools on my 4 GB / 2 core @ 2.13 ghz AMD old laptop. It's running Ubuntu 20.04 64 bit OS. Runs a lot faster than my RPi 3B.


3
General Discussion / Re: ESP32 MicroPython
« on: March 18, 2021, 05:31:02 am »
I have spent hours trying to get my DHT11 and DHT22 working on Micropython using the DHT library. The measure() call returns a ETIMEOUT with every attempt.

Has anyone gotten this to work?

You don't need to join the forum to respond. Send an e-mail to support@raspberrybasic.org with suggestions would be appreciated.

4
General Discussion / Re: ESP32 MicroPython
« on: March 17, 2021, 12:11:11 am »
ESP32-PICO-D4

Detailed Spec.

ESP32 contains two low-power Xtensa 32-bit LX6 microprocessors. (240 MHz) The internal memory includes:

* 448 KB of ROM for booting and core functions.
* 520 KB of on-chip SRAM for data and instructions.
* 8 KB of SRAM in RTC, which is called RTC FAST Memory and can be used for data storage; it is accessedby the main CPU during RTC Boot from the Deep-sleep mode.
* 8 KB of SRAM in RTC, which is called RTC SLOW Memory and can be accessed by the co-processorduring the Deep-sleep mode.
* 1 Kbit of eFuse: 256 bits are used for the system (MAC address and chip configuration) and the remaining768 bits are reserved for customer applications, including flash-encryption and chip-ID
* 4 MB Flash
* Wi-Fi and Bluetooth
$10


ESP32-DEVKITC32D

Detailed Spec.

ESP32-D0WD contains a dual-core Xtensa 32-bit LX6 MCU microprocessor. (240 MHz) The internal memory includes:

* 448 KB of ROM for booting and core functions.
* 520 KB of on-chip SRAM for data and instructions.
* 8 KB of SRAM in RTC, which is called RTC FAST Memory and can be used for data storage; it is accessedby the main CPU during RTC Boot from the Deep-sleep mode.
* 8 KB of SRAM in RTC, which is called RTC SLOW Memory and can be accessed by the co-processorduring the Deep-sleep mode.
* 1 Kbit of eFuse: 256 bits are used for the system (MAC address and chip configuration) and the remaining768 bits are reserved for customer applications, including flash-encryption and chip-ID.
* 4 MB Flash
* Wi-Fi and Bluetooth
$10


Raspberry Pi Pico

* Dual-core Arm Cortex-M0+ processor, flexible clock running up to 133 MHz
* 264KB on-chip SRAM
* 2MB on-board QSPI Flash
$4

5
General Discussion / Re: ESP32 MicroPython
« on: March 16, 2021, 08:33:03 pm »
This is a ESP32-PICO MicroPython pystone_lowmem benchmark example. This also shows how to use upip to install additional libraries.

Code: Python
  1. >>>
  2. MPY: soft reboot
  3. MicroPython v1.14 on 2021-02-02; ESP32 module with ESP32
  4. Type "help()" for more information.
  5. >>> import network
  6. >>> sta_if = network.WLAN(network.STA_IF)
  7. >>> sta_if.active()
  8. False
  9. >>> sta_if.active(True)
  10. True
  11. >>>
  12. >>> sta_if.scan()
  13. [(b'jrs', b'\xd8\x07\xb6\xf8\xb1\x97', 10, -31, 4, False), (b'BillingsHouse', b'D\x1c\x12\xd8\x99\x96', 1, -64, 3, False), (b'Nika', b'\xec\xaa\xa02\xb0h', 6, -79, 3, False), (b'chicken shit', b'\xd4\xab\x82\xc7\x8d\x92', 1, -84, 3, False), (b'AOL', b'\xbc\x9bh\xa6\x0f\x18', 11, -84, 3, False), (b'2018NEW3beginsYIP!', b'\xd4\xab\x82\xc3\x15\xea', 11, -84, 3, False), (b'My Bell', b'\x80>H\xb7o\xc5', 11, -86, 4, False), (b'Anahouse', b'\x84\x00-\x03\xc1\x98', 11, -89, 3, False), (b'Guapo', b'\xac\xdbHB\xa9\x86', 11, -89, 3, False), (b'IslandHouse', b'P\xd4\xf7\x02b\x89', 2, -90, 3, False), (b'password', b'<z\x8a9\xce`', 1, -91, 3, False), (b'BK WiFi', b'\\\xe3\x0e\xbc\x13\xb5', 6, -91, 3, False), (b'UmbrellaCorp', b'\x84\xd8\x1bfu\xce', 1, -95, 3, False)]
  14. >>> sta_if.connect('jrs', 'MY_PASSWORD')
  15. >>> sta_if.isconnected()
  16. True
  17. >>> import upip
  18. >>> upip.install("micropython-pystone_lowmem")
  19. Installing to: /lib/
  20. Warning: micropython.org SSL certificate is not validated
  21. Installing micropython-pystone_lowmem 3.4.2.post4 from https://micropython.org/pi/pystone_lowmem/pystone_lowmem-3.4.2.post4.tar.gz
  22. >>> import pystone_lowmem
  23. >>>
  24. >>> pystone_lowmem.main()
  25. Pystone(1.2) time for 500 passes = 536ms
  26. This machine benchmarks at 932 pystones/second
  27. >>>
  28.  

This is the same benchmark but using my ESP32-DEVKITC32D board and increasing the processor frequency rate.

Code: Python
  1. >>>
  2. MPY: soft reboot
  3. MicroPython v1.14 on 2021-02-02; ESP32 module with ESP32
  4. Type "help()" for more information.
  5. >>> import network
  6. >>> sta_if = network.WLAN(network.STA_IF)
  7. >>> sta_if.active()
  8. False
  9. >>> sta_if.active(True)
  10. True
  11. >>> sta_if.connect('jrs', 'MY_PASSWORD')
  12. >>> sta_if.isconnected()
  13. True
  14. >>> import upip
  15. >>> upip.install("micropython-pystone_lowmem")
  16. Installing to: /lib/
  17. Warning: micropython.org SSL certificate is not validated
  18. Installing micropython-pystone_lowmem 3.4.2.post4 from https://micropython.org/pi/pystone_lowmem/pystone_lowmem-3.4.2.post4.tar.gz
  19. >>> import pystone_lowmem
  20. >>> pystone_lowmem.main()
  21. Pystone(1.2) time for 500 passes = 537ms
  22. This machine benchmarks at 931 pystones/second
  23. >>> import machine
  24. >>> machine.freq(240000000)
  25. >>> pystone_lowmem.main()
  26. Pystone(1.2) time for 500 passes = 432ms
  27. This machine benchmarks at 1157 pystones/second
  28. >>>
  29.  

I retried the ESP32-PICO (not related to RPi Pico) and increased the frequency to 240000000 it ran faster than my ESP32-DEVKITC32D board.  :o


>>> pystone_lowmem.main()
Pystone(1.2) time for 500 passes = 428ms
This machine benchmarks at 1168 pystones/second
>>>


I need to do a side-by-side comparison to see what makes them different.

I found a post that shows the RPI Pico pystone_lowmem results.


>>> exec(open('Pi_Pico_Pystone_lowmem.py').read())
Pystone(1.2) time for 500 passes = 460ms
This machine benchmarks at 1086 pystones/second

>>>


6
General Discussion / Re: ESP32 MicroPython
« on: March 15, 2021, 09:28:47 pm »
I got MicroPython running on my ESP32-PICO board. The sensor blinks each time it's scanned.

Picture


pi@RPi3B:~/esp $ /home/pi/esp/esp-idf/components/esptool_py/esptool/esptool.py --port /dev/ttyUSB0 erase_flash
esptool.py v3.1-dev
Serial port /dev/ttyUSB0
Connecting........_
Detecting chip type... ESP32
Chip is ESP32-PICO-D4 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, Embedded Flash, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: d8:a0:1d:5f:c1:54
Uploading stub...
Running stub...
Stub running...
Erasing flash (this may take a while)...
Chip erase completed successfully in 5.1s
Hard resetting via RTS pin...
pi@RPi3B:~/esp $

pi@RPi3B:~/esp $ /home/pi/esp/esp-idf/components/esptool_py/esptool/esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 460800 write_flash -z 0x1000 esp32-idf4-20210202-v1.14.bin
esptool.py v3.1-dev
Serial port /dev/ttyUSB0
Connecting....
Chip is ESP32-PICO-D4 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, Embedded Flash, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: d8:a0:1d:5f:c1:54
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Compressed 1484624 bytes to 951640...
Wrote 1484624 bytes (951640 compressed) at 0x00001000 in 24.2 seconds (effective 491.4 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...
pi@RPi3B:~/esp $


7
General Discussion / Re: ESP32 MicroPython
« on: March 15, 2021, 12:45:30 am »
I was able to get my DS18B20 temperature sensor to work with the ESP32-DEVKITC32D board.

The interpretive method of programming sure beats having to compile an image and flash it to the controller with each experiment.

I'm going to flash my ESP32-PICO with MicroPython to free up my faster board for more demanding projects.


>>>
paste mode; Ctrl-C to cancel, Ctrl-D to finish
=== import time, ds18x20
=== from machine import Pin
=== import onewire
===
=== ow = onewire.OneWire(Pin(12))
=== ds = ds18x20.DS18X20(ow)
=== i = 1
=== while i < 11:
===   roms = ds.scan()
===   ds.convert_temp()
===   for rom in roms:
===     print("Sensor " + str(rom) + ": " + str(ds.read_temp(rom)))
===   time.sleep_ms(2000)
===   i += 1
Sensor bytearray(b'(\xff&\xc2\x80\x17\x04\x93'): 22.375
Sensor bytearray(b'(\xff&\xc2\x80\x17\x04\x93'): 22.3125
Sensor bytearray(b'(\xff&\xc2\x80\x17\x04\x93'): 22.3125
Sensor bytearray(b'(\xff&\xc2\x80\x17\x04\x93'): 22.3125
Sensor bytearray(b'(\xff&\xc2\x80\x17\x04\x93'): 22.3125
Sensor bytearray(b'(\xff&\xc2\x80\x17\x04\x93'): 22.375
Sensor bytearray(b'(\xff&\xc2\x80\x17\x04\x93'): 22.375
Sensor bytearray(b'(\xff&\xc2\x80\x17\x04\x93'): 22.375
Sensor bytearray(b'(\xff&\xc2\x80\x17\x04\x93'): 22.375
Sensor bytearray(b'(\xff&\xc2\x80\x17\x04\x93'): 22.375
>>> print(rom)
bytearray(b'(\xff&\xc2\x80\x17\x04\x93')
>>> print(roms)
[bytearray(b'(\xff&\xc2\x80\x17\x04\x93')]
>>> print(ow)
<OneWire object at 3ffe5360>
>>> print(ds)
<DS18X20 object at 3ffe5370>
>>>


8
General Discussion / ESP32 MicroPython
« on: March 14, 2021, 09:35:57 am »
I was able to get MicroPython loaded on my ESP32-DEVKITC32D board. I'm using Putty on the RPi 3B to connect via /dev/ttyUSB0.


>>> help('modules')
__main__          gc                ubinascii         urandom
_boot             inisetup          ubluetooth        ure
_onewire          machine           ucollections      urequests
_thread           math              ucryptolib        uselect
_uasyncio         micropython       uctypes           usocket
_webrepl          neopixel          uerrno            ussl
apa106            network           uhashlib          ustruct
btree             ntptime           uheapq            usys
builtins          onewire           uio               utime
cmath             uarray            ujson             utimeq
dht               uasyncio/__init__ umqtt/robust      uwebsocket
ds18x20           uasyncio/core     umqtt/simple      uzlib
esp               uasyncio/event    uos               webrepl
esp32             uasyncio/funcs    upip              webrepl_setup
flashbdev         uasyncio/lock     upip_utarfile     websocket_helper
framebuf          uasyncio/stream   upysh
Plus any modules on the filesystem
>>>
>>> machine.freq(240000000)
>>> machine.freq()
240000000
>>>





9
Blassic / Re: Blassic
« on: March 10, 2021, 10:07:59 pm »
Welcome to the RaspberryBASIC forum Julian.

I setup a sub-board for your basic, made you the moderator and moved your first post to your new board.

Do you have a repository for your BASIC? If not I would be happy to set one up for you on the basic-sandbox.us site.


10
General Discussion / Re: RPI Zero Portable
« on: March 08, 2021, 04:58:49 am »
This is an example of using the OpenWeather API with Curl and the ScriptBasic LIKE function to parse the returned JSON response.

Note: I dislike the ScriptBasic function name JOKER().

Code: Script BASIC
  1. ' OpenWeather - Curl Example
  2.  
  3. IMPORT curl.bas
  4.  
  5. FUNCTION MATCH(segment)
  6.   MATCH = JOKER(segment)
  7. END FUNCTION
  8.  
  9. place = COMMAND()
  10.  
  11. ch = curl::init()
  12. curl::option(ch, "URL", "http://api.openweathermap.org/data/2.5/weather?q=" & place & "&units=imperial&appid=72405563bf538d7ce629baf2a9766e70")
  13. curl::option(ch, "CUSTOMREQUEST", "GET")
  14. response = curl::perform(ch)
  15. curl::finish(ch)
  16.  
  17. PRINT "\n", response,"\n\n"
  18.  
  19. IF response LIKE "*lon\":*,\"lat\":*}*temp\":*,*pressure\":*,*humidity\":*}*dt\":*,*country\":\"*\"*timezone\":*,*name\":\"*\"*" THEN
  20.   PRINT "Country:    ", MATCH(13), "\n"
  21.   PRINT "City:       ", MATCH(17), "\n"
  22.   PRINT "Longitude:  ", MATCH(2), "\n"
  23.   PRINT "Latitude:   ", MATCH(3), "\n"
  24.   PRINT "Date/Time:  ", FORMATDATE("MM/DD/YEAR 0H:0m:0s", MATCH(11) + MATCH(15)), "\n"
  25.   PRINT "Tempreture: ", MATCH(5), " F\n"
  26.   PRINT "Pressure:   ", MATCH(7), " hPa\n"
  27.   PRINT "Humidity:   ", MATCH(9), " %\n"
  28. END IF
  29.  


pi@raspberrypi:~/sb/examples $ time scriba curlweather.sb Anacortes,US

{"coord":{"lon":-122.6127,"lat":48.5126},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"base":"stations","main":{"temp":45.27,"feels_like":34.83,"temp_min":42.01,"temp_max":48.2,"pressure":1016,"humidity":53},"visibility":10000,"wind":{"speed":11.5,"deg":60},"clouds":{"all":1},"dt":1615229908,"sys":{"type":1,"id":3524,"country":"US","sunrise":1615214245,"sunset":1615255505},"timezone":-28800,"id":5785657,"name":"Anacortes","cod":200}

Country:    US
City:       Anacortes
Longitude:  -122.6127
Latitude:   48.5126
Date/Time:  3/8/2021 10:58:28
Tempreture: 45.27 F
Pressure:   1016 hPa
Humidity:   53 %

real    0m0.437s
user    0m0.091s
sys     0m0.073s
pi@raspberrypi:~/sb/examples $ time scriba curlweather.sb New York,US

{"coord":{"lon":-74.006,"lat":40.7143},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"base":"stations","main":{"temp":40.05,"feels_like":30.9,"temp_min":37.4,"temp_max":42.8,"pressure":1030,"humidity":26},"visibility":10000,"wind":{"speed":5.75,"deg":0},"clouds":{"all":1},"dt":1615229912,"sys":{"type":1,"id":4610,"country":"US","sunrise":1615202327,"sunset":1615244097},"timezone":-18000,"id":5128581,"name":"New York","cod":200}

Country:    US
City:       New York
Longitude:  -74.006
Latitude:   40.7143
Date/Time:  3/8/2021 13:58:32
Tempreture: 40.05 F
Pressure:   1030 hPa
Humidity:   26 %

real    0m0.332s
user    0m0.120s
sys     0m0.049s
pi@raspberrypi:~/sb/examples $ time scriba curlweather.sb London,GB

{"coord":{"lon":-0.1257,"lat":51.5085},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04n"}],"base":"stations","main":{"temp":46.92,"feels_like":42.51,"temp_min":45,"temp_max":48.2,"pressure":1022,"humidity":53},"visibility":10000,"wind":{"speed":1.14,"deg":0},"clouds":{"all":100},"dt":1615230315,"sys":{"type":1,"id":1414,"country":"GB","sunrise":1615185018,"sunset":1615225950},"timezone":0,"id":2643743,"name":"London","cod":200}

Country:    GB
City:       London
Longitude:  -0.1257
Latitude:   51.5085
Date/Time:  3/8/2021 19:05:15
Tempreture: 46.92 F
Pressure:   1022 hPa
Humidity:   53 %

real    0m0.333s
user    0m0.111s
sys     0m0.053s
pi@raspberrypi:~/sb/examples $


11
General Discussion / Re: RPI Zero Portable
« on: March 07, 2021, 09:40:05 pm »
This is an example of using the MySQL extension module with ScriptBasic on the RPi Zero.

Code: Script BASIC
  1. ' MySQL Demo Program
  2.  
  3. INCLUDE mysql.bas
  4.  
  5. dbh = mysql::RealConnect("localhost","root","mypswd","classicmodels")
  6. mysql::query(dbh,"SELECT * FROM products WHERE productLine = 'Classic Cars'")
  7.  
  8. WHILE mysql::FetchHash(dbh,column)
  9.   PRINT column{"productCode"}," - ",column{"productName"}," - ",FORMAT("%~$###.00~",column{"MSRP"}),"\n"
  10. WEND
  11.  
  12. PRINTNL
  13. PRINT "The database handle is: ",dbh,"\n"
  14. PRINT "Affected rows by SELECT: ",mysql::AffectedRows(dbh),"\n"
  15. PRINT "Character set name is: ",mysql::CharacterSetName(dbh),"\n"
  16. PRINT "Last error is: ",mysql::ErrorMessage(dbh),"\n"
  17. PRINT "Client info is: ",mysql::GetClientInfo(),"\n"
  18. PRINT "Host info is: ",mysql::GetHostInfo(dbh),"\n"
  19. PRINT "Proto info is: ",mysql::GetProtoInfo(dbh),"\n"
  20. PRINT "Server info is: ",mysql::GetServerInfo(dbh),"\n"
  21. PRINT "PING result: ",mysql::Ping(dbh),"\n"
  22. PRINT "Thread ID: ",mysql::ThreadId(dbh),"\n"
  23. PRINT "Status is: ",mysql::Stat(dbh),"\n"
  24.  
  25. mysql::Close(dbh)
  26.  


pi@raspberrypi:~/sb/examples $ scriba mysql_demo.sb
S10_1949 - 1952 Alpine Renault 1300 - $214.30
S10_4757 - 1972 Alfa Romeo GTA - $136.00
S10_4962 - 1962 LanciaA Delta 16V - $147.74
S12_1099 - 1968 Ford Mustang - $194.57
S12_1108 - 2001 Ferrari Enzo - $207.80
S12_3148 - 1969 Corvair Monza - $151.08
S12_3380 - 1968 Dodge Charger - $117.44
S12_3891 - 1969 Ford Falcon - $173.02
S12_3990 - 1970 Plymouth Hemi Cuda - $ 79.80
S12_4675 - 1969 Dodge Charger - $115.16
S18_1129 - 1993 Mazda RX-7 - $141.54
S18_1589 - 1965 Aston Martin DB5 - $124.44
S18_1889 - 1948 Porsche 356-A Roadster - $ 77.00
S18_1984 - 1995 Honda Civic - $142.25
S18_2238 - 1998 Chrysler Plymouth Prowler - $163.73
S18_2870 - 1999 Indy 500 Monte Carlo SS - $132.00
S18_3232 - 1992 Ferrari 360 Spider red - $169.34
S18_3233 - 1985 Toyota Supra - $107.57
S18_3278 - 1969 Dodge Super Bee - $ 80.41
S18_3482 - 1976 Ford Gran Torino - $146.99
S18_3685 - 1948 Porsche Type 356 Roadster - $141.28
S18_4027 - 1970 Triumph Spitfire - $143.62
S18_4721 - 1957 Corvette Convertible - $148.80
S18_4933 - 1957 Ford Thunderbird - $ 71.27
S24_1046 - 1970 Chevy Chevelle SS 454 - $ 73.49
S24_1444 - 1970 Dodge Coronet - $ 57.80
S24_1628 - 1966 Shelby Cobra 427 S/C - $ 50.31
S24_2766 - 1949 Jaguar XK 120 - $ 90.87
S24_2840 - 1958 Chevy Corvette Limited Edition - $ 35.36
S24_2887 - 1952 Citroen-15CV - $117.44
S24_2972 - 1982 Lamborghini Diablo - $ 37.76
S24_3191 - 1969 Chevrolet Camaro Z28 - $ 85.61
S24_3371 - 1971 Alpine Renault 1600s - $ 61.23
S24_3432 - 2002 Chevy Corvette - $107.08
S24_3856 - 1956 Porsche 356A Coupe - $140.43
S24_4048 - 1992 Porsche Cayenne Turbo Silver - $118.28
S24_4620 - 1961 Chevrolet Impala - $ 80.84
S700_2824 - 1982 Camaro Z28 - $101.15

The database handle is: 1
Affected rows by SELECT: 38
Character set name is: latin1
Last error is:
Client info is: 10.3.27
Host info is: Localhost via UNIX socket
Proto info is: 10
Server info is: 10.3.27-MariaDB-0+deb10u1
PING result: -1
Thread ID: 0
Status is: Uptime: 8093  Threads: 8  Questions: 486  Slow queries: 0  Opens: 31  Flush tables: 1  Open tables: 25  Queries per second avg: 0.060
pi@raspberrypi:~/sb/examples $


12
General Discussion / Re: RPI Zero Portable
« on: March 07, 2021, 06:12:35 pm »
I install PHP 7.3 for Apache and phpMyAdmin. With my RPi mapped drive I can use UltraEdit on my Windows laptop. Running Raspian Lite seems to make the RPi Zero run efficiently. I think I've created a nice Linux sidekick for my Windows 10 laptop.  8)

13
General Discussion / Re: RPI Zero Portable
« on: March 07, 2021, 05:57:00 am »
Mapping Network Drive Over SSH in Windows

SSHFS (SSH Filesystem) is a filesystem client to mount and interact with directories and files located on a remote server or workstation over a normal ssh connection. The client interacts with the remote file system via the SSH File Transfer Protocol (SFTP), a network protocol providing file access, file transfer, and file management functionality over any reliable data stream that was designed as an extension of the Secure Shell protocol (SSH) version 2.0.

Makerlab Web Site (Free & Open Source)

The attached screen shot is my Windows 10 file explorer mapped (drive R:) to my home directory of my dongle RPi Zero.

14
General Discussion / RPI Zero Portable
« on: March 06, 2021, 09:20:26 pm »
I picked up a dongle like adapter for my RPi Zero running Raspian Lite. This gives me a USB portable Linux I connect to via WIFI / SSH.


PS C:\WINDOWS\system32> ssh pi@192.168.0.193
pi@192.168.0.193's password:
Linux raspberrypi 5.10.17+ #1403 Mon Feb 22 11:26:13 GMT 2021 armv6l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sat Mar  6 13:01:58 2021 from 192.168.0.191
pi@raspberrypi:~ $

pi@raspberrypi:~ $ free --mega
              total        used        free      shared  buff/cache   available
Mem:            450         110          93           7         246         278
Swap:           104           3         101
pi@raspberrypi:~ $ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       117G  1.8G  111G   2% /
devtmpfs        183M     0  183M   0% /dev
tmpfs           216M     0  216M   0% /dev/shm
tmpfs           216M  3.1M  213M   2% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           216M     0  216M   0% /sys/fs/cgroup
/dev/mmcblk0p1  253M   48M  205M  19% /boot
tmpfs            44M     0   44M   0% /run/user/1000
pi@raspberrypi:~ $


Installed:

  • ScriptBasic source and runtime
  • MySQL (MariaDB) Server
  • Apache2 Web Server (running on WIFI connection)

15
ScriptBasic / Re: Pico
« on: March 03, 2021, 07:49:12 am »
FreeRTOS Real Time Stats Example

FreeRTOS provides the function vTaskGetRunTimeStats() to obtain CPU usage statistics of tasks. However, these statistics are with respect to the entire runtime of FreeRTOS (i.e. run time stats). Furthermore, statistics of vTaskGetRunTimeStats() are only valid whilst the timer for run time statistics has not overflowed.

This example demonstrates how to get CPU usage statistics of tasks with respect to a specified duration (i.e. real time stats) rather than over the entire runtime of FreeRTOS. The print_real_time_stats() function of this example demonstrates how this can be achieved.

Example Breakdown

Spin tasks

During the examples initialization process, multiple spin tasks are created. These tasks will simply spin a certain number of CPU cycles to consume CPU time, then block for a predetermined period.

Understanding the stats

From the log output, it can be seen that the spin tasks consume nearly an equal amount of time over the specified stats collection period of print_real_time_stats(). The real time stats also display the CPU time consumption of other tasks created by default in ESP-IDF (e.g. IDLE and ipc tasks).

Code: C
  1. /* FreeRTOS Real Time Stats Example
  2.  
  3.    This example code is in the Public Domain (or CC0 licensed, at your option.)
  4.  
  5.    Unless required by applicable law or agreed to in writing, this
  6.    software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  7.    CONDITIONS OF ANY KIND, either express or implied.
  8. */
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include "freertos/FreeRTOS.h"
  13. #include "freertos/task.h"
  14. #include "freertos/semphr.h"
  15. #include "esp_err.h"
  16.  
  17. #define NUM_OF_SPIN_TASKS   6
  18. #define SPIN_ITER           500000  //Actual CPU cycles used will depend on compiler optimization
  19. #define SPIN_TASK_PRIO      2
  20. #define STATS_TASK_PRIO     3
  21. #define STATS_TICKS         pdMS_TO_TICKS(1000)
  22. #define ARRAY_SIZE_OFFSET   5   //Increase this if print_real_time_stats returns ESP_ERR_INVALID_SIZE
  23.  
  24. static char task_names[NUM_OF_SPIN_TASKS][configMAX_TASK_NAME_LEN];
  25. static SemaphoreHandle_t sync_spin_task;
  26. static SemaphoreHandle_t sync_stats_task;
  27.  
  28. /**
  29.  * @brief   Function to print the CPU usage of tasks over a given duration.
  30.  *
  31.  * This function will measure and print the CPU usage of tasks over a specified
  32.  * number of ticks (i.e. real time stats). This is implemented by simply calling
  33.  * uxTaskGetSystemState() twice separated by a delay, then calculating the
  34.  * differences of task run times before and after the delay.
  35.  *
  36.  * @note    If any tasks are added or removed during the delay, the stats of
  37.  *          those tasks will not be printed.
  38.  * @note    This function should be called from a high priority task to minimize
  39.  *          inaccuracies with delays.
  40.  * @note    When running in dual core mode, each core will correspond to 50% of
  41.  *          the run time.
  42.  *
  43.  * @param   xTicksToWait    Period of stats measurement
  44.  *
  45.  * @return
  46.  *  - ESP_OK                Success
  47.  *  - ESP_ERR_NO_MEM        Insufficient memory to allocated internal arrays
  48.  *  - ESP_ERR_INVALID_SIZE  Insufficient array size for uxTaskGetSystemState. Trying increasing ARRAY_SIZE_OFFSET
  49.  *  - ESP_ERR_INVALID_STATE Delay duration too short
  50.  */
  51. static esp_err_t print_real_time_stats(TickType_t xTicksToWait)
  52. {
  53.     TaskStatus_t *start_array = NULL, *end_array = NULL;
  54.     UBaseType_t start_array_size, end_array_size;
  55.     uint32_t start_run_time, end_run_time;
  56.     esp_err_t ret;
  57.  
  58.     //Allocate array to store current task states
  59.     start_array_size = uxTaskGetNumberOfTasks() + ARRAY_SIZE_OFFSET;
  60.     start_array = malloc(sizeof(TaskStatus_t) * start_array_size);
  61.     if (start_array == NULL) {
  62.         ret = ESP_ERR_NO_MEM;
  63.         goto exit;
  64.     }
  65.     //Get current task states
  66.     start_array_size = uxTaskGetSystemState(start_array, start_array_size, &start_run_time);
  67.     if (start_array_size == 0) {
  68.         ret = ESP_ERR_INVALID_SIZE;
  69.         goto exit;
  70.     }
  71.  
  72.     vTaskDelay(xTicksToWait);
  73.  
  74.     //Allocate array to store tasks states post delay
  75.     end_array_size = uxTaskGetNumberOfTasks() + ARRAY_SIZE_OFFSET;
  76.     end_array = malloc(sizeof(TaskStatus_t) * end_array_size);
  77.     if (end_array == NULL) {
  78.         ret = ESP_ERR_NO_MEM;
  79.         goto exit;
  80.     }
  81.     //Get post delay task states
  82.     end_array_size = uxTaskGetSystemState(end_array, end_array_size, &end_run_time);
  83.     if (end_array_size == 0) {
  84.         ret = ESP_ERR_INVALID_SIZE;
  85.         goto exit;
  86.     }
  87.  
  88.     //Calculate total_elapsed_time in units of run time stats clock period.
  89.     uint32_t total_elapsed_time = (end_run_time - start_run_time);
  90.     if (total_elapsed_time == 0) {
  91.         ret = ESP_ERR_INVALID_STATE;
  92.         goto exit;
  93.     }
  94.  
  95.     printf("| Task | Run Time | Percentage\n");
  96.     //Match each task in start_array to those in the end_array
  97.     for (int i = 0; i < start_array_size; i++) {
  98.         int k = -1;
  99.         for (int j = 0; j < end_array_size; j++) {
  100.             if (start_array[i].xHandle == end_array[j].xHandle) {
  101.                 k = j;
  102.                 //Mark that task have been matched by overwriting their handles
  103.                 start_array[i].xHandle = NULL;
  104.                 end_array[j].xHandle = NULL;
  105.                 break;
  106.             }
  107.         }
  108.         //Check if matching task found
  109.         if (k >= 0) {
  110.             uint32_t task_elapsed_time = end_array[k].ulRunTimeCounter - start_array[i].ulRunTimeCounter;
  111.             uint32_t percentage_time = (task_elapsed_time * 100UL) / (total_elapsed_time * portNUM_PROCESSORS);
  112.             printf("| %s | %d | %d%%\n", start_array[i].pcTaskName, task_elapsed_time, percentage_time);
  113.         }
  114.     }
  115.  
  116.     //Print unmatched tasks
  117.     for (int i = 0; i < start_array_size; i++) {
  118.         if (start_array[i].xHandle != NULL) {
  119.             printf("| %s | Deleted\n", start_array[i].pcTaskName);
  120.         }
  121.     }
  122.     for (int i = 0; i < end_array_size; i++) {
  123.         if (end_array[i].xHandle != NULL) {
  124.             printf("| %s | Created\n", end_array[i].pcTaskName);
  125.         }
  126.     }
  127.     ret = ESP_OK;
  128.  
  129. exit:    //Common return path
  130.     free(start_array);
  131.     free(end_array);
  132.     return ret;
  133. }
  134.  
  135. static void spin_task(void *arg)
  136. {
  137.     xSemaphoreTake(sync_spin_task, portMAX_DELAY);
  138.     while (1) {
  139.         //Consume CPU cycles
  140.         for (int i = 0; i < SPIN_ITER; i++) {
  141.             __asm__ __volatile__("NOP");
  142.         }
  143.         vTaskDelay(pdMS_TO_TICKS(100));
  144.     }
  145. }
  146.  
  147. static void stats_task(void *arg)
  148. {
  149.     xSemaphoreTake(sync_stats_task, portMAX_DELAY);
  150.  
  151.     //Start all the spin tasks
  152.     for (int i = 0; i < NUM_OF_SPIN_TASKS; i++) {
  153.         xSemaphoreGive(sync_spin_task);
  154.     }
  155.  
  156.     //Print real time stats periodically
  157.     while (1) {
  158.         printf("\n\nGetting real time stats over %d ticks\n", STATS_TICKS);
  159.         if (print_real_time_stats(STATS_TICKS) == ESP_OK) {
  160.             printf("Real time stats obtained\n");
  161.         } else {
  162.             printf("Error getting real time stats\n");
  163.         }
  164.         vTaskDelay(pdMS_TO_TICKS(1000));
  165.     }
  166. }
  167.  
  168. void app_main(void)
  169. {
  170.     //Allow other core to finish initialization
  171.     vTaskDelay(pdMS_TO_TICKS(100));
  172.  
  173.     //Create semaphores to synchronize
  174.     sync_spin_task = xSemaphoreCreateCounting(NUM_OF_SPIN_TASKS, 0);
  175.     sync_stats_task = xSemaphoreCreateBinary();
  176.  
  177.     //Create spin tasks
  178.     for (int i = 0; i < NUM_OF_SPIN_TASKS; i++) {
  179.         snprintf(task_names[i], configMAX_TASK_NAME_LEN, "spin%d", i);
  180.         xTaskCreatePinnedToCore(spin_task, task_names[i], 1024, NULL, SPIN_TASK_PRIO, NULL, tskNO_AFFINITY);
  181.     }
  182.  
  183.     //Create and start stats task
  184.     xTaskCreatePinnedToCore(stats_task, "stats", 4096, NULL, STATS_TASK_PRIO, NULL, tskNO_AFFINITY);
  185.     xSemaphoreGive(sync_stats_task);
  186. }
  187.  


Getting real time stats over 100 ticks
| Task | Run Time | Percentage
| stats | 1468 | 0%
| spin3 | 209100 | 10%
| spin4 | 225361 | 11%
| spin5 | 225360 | 11%
| spin1 | 217281 | 10%
| spin2 | 225387 | 11%
| spin0 | 225371 | 11%
| IDLE | 269997 | 13%
| IDLE | 394701 | 19%
| esp_timer | 0 | 0%
| ipc1 | 0 | 0%
| ipc0 | 0 | 0%
Real time stats obtained


Getting real time stats over 100 ticks
| Task | Run Time | Percentage
| stats | 988 | 0%
| spin3 | 225354 | 11%
| spin1 | 225357 | 11%
| IDLE | 443980 | 22%
| IDLE | 202904 | 10%
| spin2 | 225354 | 11%
| spin5 | 225355 | 11%
| spin0 | 225354 | 11%
| spin4 | 225354 | 11%
| ipc0 | 0 | 0%
| esp_timer | 0 | 0%
| ipc1 | 0 | 0%
Real time stats obtained


Getting real time stats over 100 ticks
| Task | Run Time | Percentage
| stats | 965 | 0%
| spin1 | 225354 | 11%
| IDLE | 202929 | 10%
| IDLE | 443980 | 22%
| spin2 | 225354 | 11%
| spin5 | 225355 | 11%
| spin0 | 225354 | 11%
| spin3 | 225355 | 11%
| spin4 | 225354 | 11%
| ipc1 | 0 | 0%
| ipc0 | 0 | 0%
| esp_timer | 0 | 0%
Real time stats obtained


Getting real time stats over 100 ticks
| Task | Run Time | Percentage
| stats | 965 | 0%
| IDLE | 443980 | 22%
| IDLE | 202929 | 10%
| spin2 | 225354 | 11%
| spin5 | 225355 | 11%
| spin0 | 225354 | 11%
| spin3 | 225355 | 11%
| spin1 | 225354 | 11%
| spin4 | 225354 | 11%
| esp_timer | 0 | 0%
| ipc1 | 0 | 0%
| ipc0 | 0 | 0%
Real time stats obtained


Pages: [1] 2 3 ... 15