GPIO library

Discussions related specifically to the Windows, Linux (86), Mac OS-X and Raspberry Pi editions of BB4W and BBCSDL
Post Reply
agw
Posts: 3
Joined: Fri 06 Apr 2018, 11:39

GPIO library

Post by agw » Sun 08 Apr 2018, 22:20

I haven't done any coding (programming ?) since the mid 80's, and then only BBC Basic and 6502 code, so perhaps I'm not really a suitable person for a forum like this, but never mind. I'd like to say thank you to Richard Russell for the support he has given to BBC Basic, and the continued existence of this forum.

I was concerned how my central heating system was performing when the house was empty, and investigated a 4 channel temperature logger. Having heard of the Raspberry Pi, I thought it might be interesting to use a Pi instead. In days of yore one could have used thermocouples with a T/C amp, RTD's or thermistors with associated electronics to the 4 channel analogue I/P on the Beeb. The Pi communicates with the outside world differently, in a way I am not familiar with, so there is more to explore here. I found this type of device in several places.

http://www.reuk.co.uk/wordpress/raspber ... pberry-pi/

http://www.reuk.co.uk/wordpress/raspber ... pberry-pi/

I presume it is the same as was being discussed in the last forum.

I have not managed to install BBC Basic into Pi yet, so I have no access to the GPIO library which I understand is included. Does it enable a BBC Basic program to read the device temperature as shown in the two links I have given?

guest
Posts: 104
Joined: Mon 02 Apr 2018, 09:12

Re: GPIO library

Post by guest » Sun 08 Apr 2018, 23:17

agw wrote:
Sun 08 Apr 2018, 22:20
Does it enable a BBC Basic program to read the device temperature as shown in the two links I have given?
As far as I can see from the examples you linked to, the temperature data is returned as a simple text file so you don't need the GPIO library at all. All you should need to do, as in the example Python code listed, is periodically to read that file. Trivial to do in BBC BASIC (and pretty much any other language for that matter).

If you want to copy the Python code more closely there's an FN_split() function in BBC BASIC's stringlib library which works in a similar way to Python's split method, but equally there are many other ways in which you could achieve the same result in BASIC.

Here's an almost line-by-line translation of the Python code at your first link into BBC BASIC:

Code: Select all

      INSTALL @lib$ + "stringlib"

      REPEAT
        tempfile = OPENIN("/sys/bus/w1/devices/28-00000283c6cd/w1_slave.")
        textline1$ = GET$#tempfile
        textline2$ = GET$#tempfile
        CLOSE #tempfile
        parts = FN_split(textline2$, " ", tempdata$())
        temperature = VAL(MID$(tempdata$(9),3)) / 1000
        PRINT temperature
        WAIT 100
      UNTIL FALSE
Richard.

agw
Posts: 3
Joined: Fri 06 Apr 2018, 11:39

Re: GPIO library

Post by agw » Mon 09 Apr 2018, 22:35

Thank you Richard, for your very quick reply. We have visitors at present, so the next couple of days are spoken for. I hope then to have time to try and work things out. First task is to actually install BBC Basic on the Pi.

Phil

Post Reply