⎕ARBIN for serial comms (Pi to Beeb micro:bit)

No need to worry about going "off topic" here
Forum rules
This forum is for general chit-chat, not necessarily APL-related. However, it's not for spam or for offensive or illegal comments.

⎕ARBIN for serial comms (Pi to Beeb micro:bit)

Postby romilly on Wed Jan 18, 2017 8:46 am

I'm about to link a Raspberry Pi and a BBC micro:bit using serial comms. I'd like to use APL and ⎕arbin on the Pi end but can't find any sample code. Any suggestions?

I'll eventually need two-way serial comms but one-way would do to start with.
romilly
 
Posts: 6
Joined: Tue May 03, 2016 9:51 am

Re: ⎕ARBIN for serial comms (Pi to Beeb micro:bit)

Postby ray on Wed Jan 18, 2017 1:15 pm

Hi Romily

I have used ⎕ARBIN and ⎕ARBOUT to "talk" to the GPIO pins on the Raspberry Pi.

I no longer use ⎕ARBIN as I found that ⎕NREAD can be used instead.

Using ⎕ARBOUT has changed since Dyalog 14.0(?).
It used to take a file name (such as '/sys/class/gpio/gpio2/direction'
and '/sys/class/gpio/gpio2/value' when talking to GPIO pin 2.

With Dyalog 14.1, ⎕ARBOUT now takes a file tie number.
So my code uses this cover function:

Code: Select all
fid ARBOUT data;names;bos;tie
 ⍝ Cover function for ⎕ARBOUT
 names←(↓⎕NNAMES)~¨' '
 bos←names∊⊂fid
 :If ~∨/bos
     tie←fid ⎕NTIE 0
 :Else
     tie←⊃bos/⎕NNUMS
 :End
 tie ⎕ARBOUT data


I use ⎕UCS to convert the "text" into bytes suitable for ⎕ARBOUT.

An example of it in use:
Code: Select all
∇ pin Move_servo pcent
⍝ Writes to one of the pins controlling the servers
⍝ This code is approximately equivalent to:
⍝       ⎕SH'echo   ',pin,'=',(⍕pcent),'% > /dev/servoblaster'
 '/dev/servoblaster'ARBOUT pin,61,(⎕UCS⍕pcent),37 10   
⍝ where '='≡61 '0'≡48 '1'≡49...'%'≡37 '10'≡<Linefeed>


I hope this is of some help.

Ray
Ray Cannon
Please excuse any smelling pisstakes.
User avatar
ray
 
Posts: 95
Joined: Wed Feb 24, 2010 12:24 am
Location: Blackwater, Camberley. UK


Return to Chat

Who is online

Users browsing this forum: No registered users and 1 guest