Raspberry BASIC

Recent Posts

Pages: 1 ... 6 7 [8] 9 10
71
ScriptBasic / Re: Pico
« Last post by John Spikowski on February 28, 2021, 12:09:14 PM »
I was able to get CBASIC working with the ESP32-PICO. This is an example of random number generation and calculating the mean value. This example shows using a separate C program as a component.

Code: C
  1. #include <stdio.h>
  2. #include "esp_system.h"
  3. #include "testable.h"
  4. #include "cbasic.h"
  5.  
  6. SUB app_main(void)
  7. BEGIN_SUB
  8.   CONST int count = 32;
  9.   CONST int max = 100;
  10.   PRINT("In main application. Collecting %d random numbers from 1 to %d:\n", count, max);
  11.   DIM int AS PTR numbers = calloc(count, sizeof(numbers[0]));
  12.   DEF_FOR(int i = 0 TO i < count STEP INCR i)
  13.   BEGIN_FOR
  14.     numbers[i] = 1 + esp_random() MOD (max - 1);
  15.     PRINT("%4d ", numbers[i]);
  16.     IF ((i + 1) MOD 10 == 0) THEN
  17.       PRINT("\n");
  18.     END_IF
  19.   NEXT
  20.   DIM int AS mean = testable_mean(numbers, count);
  21.   PRINT ("\nMean: %d\n", mean);
  22.   free(numbers);
  23. END_SUB
  24.  

mean.c
Code: C
  1. #include "testable.h"
  2. #include "cbasic.h"
  3.  
  4. FUNCTION int testable_mean(const int PTR values, int count)
  5. BEGIN_FUNCTION
  6.   IF (count == 0) THEN
  7.     RETURN_FUNCTION(0);
  8.   END_IF
  9.   DIM int AS sum = 0;
  10.   DEF_FOR (int i = 0 TO i < count STEP INCR i)
  11.   BEGIN_FOR
  12.      sum += values[i];
  13.   NEXT
  14.   RETURN_FUNCTION(sum / count);
  15. END_FUNCTION
  16.  

testable.h
Code: C
  1. #pragma once
  2.  
  3. /**
  4.  * @brief Calculate arithmetic mean of integer values
  5.  * @param values  array of values
  6.  * @param count   number of elements in the array
  7.  * @return arithmetic mean of values, or zero count is zero
  8.  */
  9. int testable_mean(const int* values, int count);
  10.  


pi@RPi3B:~/esp/unit_test $ idf.py -p /dev/ttyUSB0 monitor
WARNING: Python 3 versions older than 3.6 are not supported.
Executing action: monitor
Running idf_monitor in directory /home/pi/esp/unit_test
Executing "/home/pi/.espressif/python_env/idf4.4_py3.5_env/bin/python /home/pi/esp/esp-idf/tools/idf_monitor.py -p /dev/ttyUSB0 -b 115200 --toolchain-prefix xtensa-esp32-elf- /home/pi/esp/unit_test/build/unit_test.elf -m '/home/pi/.espressif/python_env/idf4.4_py3.5_env/bin/python' '/home/pi/esp/esp-idf/tools/idf.py' '-p' '/dev/ttyUSB0'"...
--- idf_monitor on /dev/ttyUSB0 115200 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 188777542, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:6916
load:0x40078000,len:14336
ho 0 tail 12 room 4
load:0x40080400,len:3672
0x40080400: _init at ??:?

entry 0x40080678
I (30) boot: ESP-IDF v4.4-dev-4-g73db14240 2nd stage bootloader
I (30) boot: compile time 03:48:52
I (30) boot: chip revision: 1
I (34) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (41) boot.esp32: SPI Speed      : 40MHz
I (46) boot.esp32: SPI Mode       : DIO
I (50) boot.esp32: SPI Flash Size : 2MB
I (55) boot: Enabling RNG early entropy source...
I (60) boot: Partition Table:
I (64) boot: ## Label            Usage          Type ST Offset   Length
I (71) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (78) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (86) boot:  2 factory          factory app      00 00 00010000 00100000
I (93) boot: End of partition table
I (97) boot_comm: chip revision: 1, min. application chip revision: 0
I (105) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=05bbch ( 23484) map
I (121) esp_image: segment 1: paddr=00015be4 vaddr=3ffb0000 size=02860h ( 10336) load
I (126) esp_image: segment 2: paddr=0001844c vaddr=40080000 size=07bcch ( 31692) load
I (143) esp_image: segment 3: paddr=00020020 vaddr=400d0020 size=1337ch ( 78716) map
I (171) esp_image: segment 4: paddr=000333a4 vaddr=40087bcc size=02f6ch ( 12140) load
I (182) boot: Loaded app from partition at offset 0x10000
I (182) boot: Disabling RNG early entropy source...
I (194) cpu_start: Pro cpu up.
I (194) cpu_start: Starting app cpu, entry point is 0x40080f34
0x40080f34: call_start_cpu1 at /home/pi/esp/esp-idf/components/esp_system/port/cpu_start.c:143

I (0) cpu_start: App cpu up.
I (208) cpu_start: Pro cpu start user code
I (208) cpu_start: cpu freq: 160000000
I (208) cpu_start: Application information:
I (212) cpu_start: Project name:     unit_test
I (218) cpu_start: App version:      1
I (222) cpu_start: Compile time:     Feb 28 2021 03:51:29
I (228) cpu_start: ELF file SHA256:  39e44e816ec30d58...
I (234) cpu_start: ESP-IDF:          v4.4-dev-4-g73db14240
I (241) heap_init: Initializing. RAM available for dynamic allocation:
I (248) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (254) heap_init: At 3FFB3088 len 0002CF78 (179 KiB): DRAM
I (260) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (266) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (273) heap_init: At 4008AB38 len 000154C8 (85 KiB): IRAM
I (280) spi_flash: detected chip: gd
I (283) spi_flash: flash io: dio
W (287) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (301) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
In main application. Collecting 32 random numbers from 1 to 100:
  76   26   40    9   74   28   37   19   78   66
  99   75   29   63   48   22    2    1   65   37
  54   63   25   24   20   75    4   31   32   75
  30   90
Mean: 44

pi@RPi3B:~/esp/unit_test $

72
ScriptBasic / Re: Pico
« Last post by John Spikowski on February 27, 2021, 08:56:35 AM »
I was able to get the Hello World to work with my new DIYMall ESP32-PICO board. Setting this up was a job.

Code: C
  1. /* Hello World 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. #include <stdio.h>
  10. #include "sdkconfig.h"
  11. #include "freertos/FreeRTOS.h"
  12. #include "freertos/task.h"
  13. #include "esp_system.h"
  14. #include "esp_spi_flash.h"
  15.  
  16. void app_main(void)
  17. {
  18.     printf("Hello world!\n");
  19.  
  20.     /* Print chip information */
  21.     esp_chip_info_t chip_info;
  22.     esp_chip_info(&chip_info);
  23.     printf("This is %s chip with %d CPU core(s), WiFi%s%s, ",
  24.             CONFIG_IDF_TARGET,
  25.             chip_info.cores,
  26.             (chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "",
  27.             (chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : "");
  28.  
  29.     printf("silicon revision %d, ", chip_info.revision);
  30.  
  31.     printf("%dMB %s flash\n", spi_flash_get_chip_size() / (1024 * 1024),
  32.             (chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");
  33.  
  34.     printf("Minimum free heap size: %d bytes\n", esp_get_minimum_free_heap_size());
  35.  
  36.     for (int i = 10; i >= 0; i--) {
  37.         printf("Restarting in %d seconds...\n", i);
  38.         vTaskDelay(1000 / portTICK_PERIOD_MS);
  39.     }
  40.     printf("Restarting now.\n");
  41.     fflush(stdout);
  42.     esp_restart();
  43. }
  44.  


pi@RPi3B:~/esp/hello_world $ idf.py -p /dev/ttyUSB0 monitor
WARNING: Support for Python 2 is deprecated and will be removed in future versions.
Executing action: monitor
Running idf_monitor in directory /home/pi/esp/hello_world
Executing "/home/pi/.espressif/python_env/idf4.4_py2.7_env/bin/python /home/pi/esp/esp-idf/tools/idf_monitor.py -p /dev/ttyUSB0 -b 115200 --toolchain-prefix xtensa-esp32-elf- /home/pi/esp/hello_world/build/hello-world.elf -m '/home/pi/.espressif/python_env/idf4.4_py2.7_env/bin/python' '/home/pi/esp/esp-idf/tools/idf.py' '-p' '/dev/ttyUSB0'"...
--- idf_monitor on /dev/ttyUSB0 115200 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ets Jun  8 2016 00:22:57

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 188777542, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:6916
load:0x40078000,len:14336
ho 0 tail 12 room 4
load:0x40080400,len:3672
0x40080400: _init at ??:?

entry 0x40080678
I (29) boot: ESP-IDF v4.4-dev-4-g73db14240 2nd stage bootloader
I (30) boot: compile time 00:12:01
I (30) boot: chip revision: 1
I (34) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (41) boot.esp32: SPI Speed      : 40MHz
I (45) boot.esp32: SPI Mode       : DIO
I (50) boot.esp32: SPI Flash Size : 2MB
I (54) boot: Enabling RNG early entropy source...
I (60) boot: Partition Table:
I (63) boot: ## Label            Usage          Type ST Offset   Length
I (71) boot:  0 nvs              WiFi data        01 02 00009000 00006000
I (78) boot:  1 phy_init         RF data          01 01 0000f000 00001000
I (86) boot:  2 factory          factory app      00 00 00010000 00100000
I (93) boot: End of partition table
I (97) boot_comm: chip revision: 1, min. application chip revision: 0
I (104) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=05f24h ( 24356) map
I (122) esp_image: segment 1: paddr=00015f4c vaddr=3ffb0000 size=02880h ( 10368) load
I (126) esp_image: segment 2: paddr=000187d4 vaddr=40080000 size=07844h ( 30788) load
I (142) esp_image: segment 3: paddr=00020020 vaddr=400d0020 size=138e4h ( 80100) map
I (171) esp_image: segment 4: paddr=0003390c vaddr=40087844 size=032f0h ( 13040) load
I (182) boot: Loaded app from partition at offset 0x10000
I (182) boot: Disabling RNG early entropy source...
I (194) cpu_start: Pro cpu up.
I (194) cpu_start: Starting app cpu, entry point is 0x40080f30
0x40080f30: call_start_cpu1 at /home/pi/esp/esp-idf/components/esp_system/port/cpu_start.c:143

I (0) cpu_start: App cpu up.
I (208) cpu_start: Pro cpu start user code
I (208) cpu_start: cpu freq: 160000000
I (208) cpu_start: Application information:
I (213) cpu_start: Project name:     hello-world
I (218) cpu_start: App version:      1
I (223) cpu_start: Compile time:     Feb 27 2021 00:14:37
I (229) cpu_start: ELF file SHA256:  bd8ca58e2e4262a6...
I (235) cpu_start: ESP-IDF:          v4.4-dev-4-g73db14240
I (241) heap_init: Initializing. RAM available for dynamic allocation:
I (248) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (254) heap_init: At 3FFB30B8 len 0002CF48 (179 KiB): DRAM
I (260) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (267) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (273) heap_init: At 4008AB34 len 000154CC (85 KiB): IRAM
I (280) spi_flash: detected chip: gd
I (284) spi_flash: flash io: dio
W (288) spi_flash: Detected size(4096k) larger than the size in the binary image header(2048k). Using the size in the binary image header.
I (302) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
Hello world!
This is esp32 chip with 2 CPU core(s), WiFi/BT/BLE, silicon revision 1, 2MB embedded flash
Minimum free heap size: 291656 bytes
Restarting in 10 seconds...

73
ScriptBasic / Re: Pico
« Last post by John Spikowski on February 26, 2021, 08:11:27 AM »
After getting over ruining my first Pico installing the headers, my hybrid Pico arrived today. Headers, reset button and WIFI. Now to have some fun with CBASIC.
 
74
BBC BASIC / Re: BBC Micro
« Last post by John Spikowski on February 22, 2021, 07:47:32 PM »
My BBC  Microbit kit arrived today.

I just plugged it into my USB port and it went through an array of feature demos. Too cool. I can see this as a great way to get kids up and running with micro controllers without a hard core hardware and software background.

I'm looking at the C API  for use with CBASIC.
75
BBC BASIC / BBC Micro
« Last post by John Spikowski on February 17, 2021, 09:30:01 PM »
Hi Richard,

I just ordered the BBCMicro starter kit from Vilros.

Do you think BBC BASIC would run on it?

76
ScriptBasic / Re: RPi Zero
« Last post by John Spikowski on February 12, 2021, 04:51:03 AM »
My new RPi Zero WH (with preinstalled GPIO header) is setup with my breakout board. My goal is to show common used sensors with ScriptBasic. I'm still comparing the feature sets of the LG and PIGPIO libraries.
77
ScriptBasic / RPi Zero
« Last post by John Spikowski on February 03, 2021, 02:56:01 AM »
As mentioned in the Pico thread I'm focusing my embedded scripting engine efforts to the RPi Zero. I built ScriptBasic from source on the Zero and running on 32 bit Raspian.  I'm working on building a GPIO extension module based on the public domain pigpio and or lg library.

78
ScriptBasic / Re: Pico
« Last post by John Spikowski on January 31, 2021, 06:19:00 PM »
I've decided to put my ScriptBasic embedded controller efforts into the Zero. A few bucks more and not a crippled toy like the Pico. I'm sure the Pico has a purpose but I don't know what it is yet.
I have yet to discover any resemblance of an OS.

Sort of like a microwave CPU being repurposed to control the stove.
79
ScriptBasic / Re: Pico
« Last post by John Spikowski on January 30, 2021, 03:20:48 PM »
After taking a peek at the MicroPython implementation on the Pico. I can't see having to run ScripBasic in single step debug mode. C is the language best fit for the Pico.
80
ScriptBasic / Re: Pico
« Last post by John Spikowski on January 29, 2021, 09:55:11 PM »
My Pico arrived. I installed the Pico development system on my RPi 4B running Ubuntu 20.04 64 bit.

The blink example compiled and ran fine on the Pico.
Pages: 1 ... 6 7 [8] 9 10