Recent Posts

Pages: 1 [2] 3 4 ... 10
11
Scripting Languages / Re: SB π
« Last post by John on April 30, 2019, 11:58:22 AM »
Now that I got something working with the SHAT extension module, I going to revisit the GPIO extension module and see if I can get that method of access working. Since it's the C portion of the Python Sense HAT API, chances of it working with the emulator are better odds.
12
Scripting Languages / Re: SB π
« Last post by John on April 30, 2019, 12:30:25 AM »
It would be helpful if an example of sending/receiving raw bytes to the /dev/fb1 device and control the LED matrix. It seems any language that can open a file can also open the fb frame buffer device.

It's interesting that the SenseHAT board will keep the LEDs on even after you shutdown the OS. Powering off the board is the only way to turn them off. The startup LED rainbow before the OS starts is another example.
13
Scripting Languages / Re: SB π
« Last post by John on April 28, 2019, 11:47:09 PM »
Believe it or not but the following code will change the color and intensity of the Sense HAT LED's. I'm beginning to believe the fb and i2c device (file like) interface could be written in SB native.

I believe I have an extension module that returns a variable pointer and does PEEK/POKE and with PACK / UNPACK ioctl and mmap could be emulated or add those functions to the (T)tools extension module.

Code: Script BASIC
  1.  
  2. FOR x = 0 TO 129
  3.   OPEN "/dev/fb1" FOR BINARY AS #1
  4.   IF x < 129 THEN
  5.     PRINT #1, STRING(128,CHR(x))
  6.   ELSE
  7.     'Turn off LED's
  8.    PRINT #1, STRING(128,CHR(0))
  9.   END IF
  10.   CLOSE(1)
  11.   SLEEP(1)
  12. NEXT
  13.  
14
Open Forum / Re: BASIC
« Last post by John on April 28, 2019, 09:40:26 PM »
Quote from: Heater@RPi
Yes. Problem is we are trying to describe the infinite detail of the real number line in the finite space of the computer.

But wait, that cannot be. Every schoolboy knows that:

0.3 + 0.3 + 0.3 =

3/10 + 3/10 + 3/10 =

(3 + 3 + 3) / 10 =

9 / 10 =

0.9

Every schoolboy has a finite sized brain so this computation is not impossible to do accurately.

No, fact is, computers cannot do arithmetic.

Schoolboy Mode:  (On)
Code: Script BASIC
  1. PRINT FORMAT("%0.1f",0.3 + 0.3 + 0.3),"\n"
  2.  
  3. PRINT FORMAT("%0.1f",3/10 + 3/10 + 3/10), "\n"
  4.  
  5. PRINT FORMAT("%0.1f",(3 + 3 + 3) / 10),"\n"
  6.  
  7. PRINT FORMAT("%0.1f",9 / 10), "\n"
  8.  

jrs@jrs-laptop:~/sb/examples/test$ scriba dotnet.sb
0.9
0.9
0.9
0.9
jrs@jrs-laptop:~/sb/examples/test$
15
Scripting Languages / Re: SB π
« Last post by John on April 28, 2019, 04:30:05 PM »
I really like the pressure and humidity routines and output from the same author that did the led_matrix.c example. I would have used it for the SHAT module if there was code for the other sensors.
16
Scripting Languages / Re: SB π
« Last post by John on April 28, 2019, 04:18:08 PM »
This is what I get.

pi@RPi3B:~/sbrpi/sensehat $ ./led_matrix
Error (call to 'ioctl'): Inappropriate ioctl for device
pi@RPi3B:~/sbrpi/sensehat $
17
Scripting Languages / Re: SB π
« Last post by AIR on April 28, 2019, 04:11:50 PM »
The SLCD extension module will use the /dev/fb1 (frame buffer) device, The initial C reference you pointed me to use the framebuffer device driver. Can you try to get that working with the emulator?
Emulator craps out with cairo error on my pi, not interested in fixing it.
Look for the following with the emulator running:
/dev/shm/rpi-sense-emu-screen

or
/tmp/rpi-sense-emu-screen
If one of those exists, edit FILEPATH to point to it. 

You'll probably need to tweak other things

18
Scripting Languages / Re: SB π
« Last post by John on April 28, 2019, 03:43:40 PM »
The SLCD extension module will use the /dev/fb1 (frame buffer) device, The initial C reference you pointed me to use the framebuffer device driver. Can you try to get that working with the emulator?

led_matrix.c
Code: C
  1. /*
  2.  *  C code to demonstrate control of the LED matrix for the
  3.  *  Raspberry Pi Sense HAT add-on board.
  4.  *
  5.  *  Uses the mmap method to map the led device into memory
  6.  *
  7.  *  Build with:
  8.  *
  9.  *       gcc -Wall led_matrix.c -o led_matrix
  10.  *
  11.  */
  12.  
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <sys/types.h>
  16. #include <sys/stat.h>
  17. #include <unistd.h>
  18. #include <fcntl.h>
  19. #include <sys/mman.h>
  20. #include <stdint.h>
  21. #include <string.h>
  22. #include <linux/fb.h>
  23. #include <sys/ioctl.h>
  24.  
  25. #define FILEPATH "/dev/fb1"
  26. #define NUM_WORDS 64
  27. #define FILESIZE (NUM_WORDS * sizeof(uint16_t))
  28.  
  29. #define RGB565_RED 0xF800
  30.  
  31. void delay(int);
  32.  
  33. int main(void)
  34. {
  35.     int i;
  36.     int fbfd;
  37.     uint16_t *map;
  38.     uint16_t *p;
  39.     struct fb_fix_screeninfo fix_info;
  40.  
  41.     /* open the led frame buffer device */
  42.     fbfd = open(FILEPATH, O_RDWR);
  43.     if (fbfd == -1) {
  44.         perror("Error (call to 'open')");
  45.         exit(EXIT_FAILURE);
  46.     }
  47.  
  48.     /* read fixed screen info for the open device */
  49.     if (ioctl(fbfd, FBIOGET_FSCREENINFO, &fix_info) == -1) {
  50.         perror("Error (call to 'ioctl')");
  51.         close(fbfd);
  52.         exit(EXIT_FAILURE);
  53.     }
  54.  
  55.     /* now check the correct device has been found */
  56.     if (strcmp(fix_info.id, "RPi-Sense FB") != 0) {
  57.         printf("%s\n", "Error: RPi-Sense FB not found");
  58.         close(fbfd);
  59.         exit(EXIT_FAILURE);
  60.     }
  61.  
  62.     /* map the led frame buffer device into memory */
  63.     map =
  64.         mmap(NULL, FILESIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0);
  65.     if (map == MAP_FAILED) {
  66.         close(fbfd);
  67.         perror("Error mmapping the file");
  68.         exit(EXIT_FAILURE);
  69.     }
  70.  
  71.     /* set a pointer to the start of the memory area */
  72.     p = map;
  73.  
  74.     /* clear the led matrix */
  75.     memset(map, 0, FILESIZE);
  76.  
  77.     /* light it up! */
  78.     for (i = 0; i < NUM_WORDS; i++) {
  79.         *(p + i) = RGB565_RED;
  80.         delay(25);
  81.     }
  82.  
  83.     /* flash white */
  84.     for (i = 0; i < 3; i++) {
  85.         delay(250);
  86.         memset(map, 0xFF, FILESIZE);
  87.         delay(250);
  88.         memset(map, 0, FILESIZE);
  89.     }
  90.     delay(250);
  91.  
  92.     /* clear the led matrix */
  93.     memset(map, 0, FILESIZE);
  94.  
  95.     /* un-map and close */
  96.     if (munmap(map, FILESIZE) == -1) {
  97.         perror("Error un-mmapping the file");
  98.     }
  99.     close(fbfd);
  100.  
  101.     return 0;
  102. }
  103.  
  104. void delay(int t)
  105. {
  106.     usleep(t * 1000);
  107. }
  108.  

config.txt

# For more options and information see
# http://rpf.io/configtxt
# Some settings may impact device functionality. See link above for details

# uncomment if you get no picture on HDMI for a default "safe" mode
#hdmi_safe=1

# uncomment this if your display has a black border of unused pixels visible
# and your display can output without overscan
#disable_overscan=1

# uncomment the following to adjust overscan. Use positive numbers if console
# goes off screen, and negative if there is too much border
#overscan_left=16
#overscan_right=16
#overscan_top=16
#overscan_bottom=16

# uncomment to force a console size. By default it will be display's size minus
# overscan.
#framebuffer_width=1280
#framebuffer_height=720

# uncomment if hdmi display is not detected and composite is being output
hdmi_force_hotplug=1

# uncomment to force a specific HDMI mode (this will force VGA)
hdmi_group=1
hdmi_mode=31

# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes
#hdmi_drive=2

# uncomment to increase signal to HDMI, if you have interference, blanking, or
# no display
#config_hdmi_boost=4

# uncomment for composite PAL
#sdtv_mode=2

#uncomment to overclock the arm. 700 MHz is the default.
#arm_freq=800

# Uncomment some or all of these to enable the optional hardware interfaces
dtparam=i2c_arm=on
#dtparam=i2s=on
#dtparam=spi=on

# Uncomment this to enable the lirc-rpi module
#dtoverlay=lirc-rpi

# Additional overlays and parameters are documented /boot/overlays/README

# Enable audio (loads snd_bcm2835)
dtparam=audio=on

# NOOBS Auto-generated Settings:
hdmi_force_hotplug=1


19
Scripting Languages / Re: SB π
« Last post by AIR on April 28, 2019, 03:17:50 PM »
It would be cool to find a way to use this extension module with the Sense HAT emulator that comes with the RPi.
I think the emu uses the framebuffer, so unless you are using that I don't think it will work.
20
Scripting Languages / Re: SB π
« Last post by AIR on April 28, 2019, 02:41:39 PM »
Post your config.txt
Pages: 1 [2] 3 4 ... 10