Function Repository Resource:

PiTopConnect

Source Notebook

Provide Wolfram Language-based access to the pi-top Maker Architecture available for the pi-top [4]

Contributed by: Mark Braithwaite

ResourceFunction["PiTopConnect"]["Components"]

provides a full list of all supported pi-top Maker Architecture components.

ResourceFunction["PiTopConnect"]["Initialize",{{"port1","componentType1"},}]

initializes the "componentTypei" that is plugged into "porti" on the base plate, allowing its use.

ResourceFunction["PiTopConnect"]["Initialized"]

provides a full list of all initialized components and their current state.

ResourceFunction["PiTopConnect"]["Read",{"port1",}]

returns the status of the components in the "porti" provided.

ResourceFunction["PiTopConnect"]["Write",{{"port1",status1},}]

sets each of the components in "porti" to the provided statusi and return their new status.

ResourceFunction["PiTopConnect"]["Stop"]

clears all stored information related to the components used.

Details and Options

This functionality only works on the pi-top[4] and with its pi-top Maker Architecture components.
All components need initilizing before use.
Supported component types can be found in the table below (please use the string name as shown):
Component NamePort TypePossible Status
"Led"DTrue / False
"SoundSensor"A≥0
"UltrasonicSensor"A≥0
"LightSensor"A≥0
"Buzzer"DTrue / False
"Potentiometer"A≥0
"Button"DTrue / False
Port type in the above table represents the labels found on the pi-top foundation plate, where A represents analogue and D is digital.
Only "Led", "Buzzer" and "Button" support the "Write" command.
All the sensors support the "Read" command.
Port names should always be strings, e.g. "D4", as labeled on the foundation plate.
Status returns for all function calls will be in the format {"port","componentType",status}, allowing its direct reuse in further function calls.

Examples

Basic Examples (5) 

Start by checking which component types are currently supported:

In[1]:=
ResourceFunction["PiTopConnect"]["Components"]
Out[1]=

Initialize your chosen component by providing its port and component type, in this case an Led, which starts turned off (False):

In[2]:=
ResourceFunction["PiTopConnect"]["Initialize", {{"D4", "Led"}}]
Out[2]=

We can check which components have been initialized using the following:

In[3]:=
ResourceFunction["PiTopConnect"]["Initialized"]
Out[3]=

Now use the "Write" command to turn that Led on (set it to True):

In[4]:=
ResourceFunction["PiTopConnect"]["Write", {{"D4", True}}]
Out[4]=

Now to check if a button is currently being pressed:

In[5]:=
ResourceFunction["PiTopConnect"]["Read", {"D4"}]
Out[5]=

Scope (3) 

The "Initialize" function can take multiple components:

In[6]:=
ResourceFunction[
 "PiTopConnect"]["Initialize", {{"D4", "Led"}, {"D0", "Button"}, {"A0", "UltrasonicSensor"}}]
Out[6]=

The "Read" function can take multiple component ports:

In[7]:=
ResourceFunction["PiTopConnect"]["Read", {"D4", "D0", "A0", "D1"}]
Out[7]=

The "Write" function can take multiple components and their new status:

In[8]:=
ResourceFunction[
 "PiTopConnect"]["Write", {{"D4", True}, {"D1", True}}]
In[9]:=
{{"D4", "Led", True}, {"D1", "Buzzer", True}}

Neat Examples (1) 

You can create a proximity sensor using three LEDs (D0, D1, D2) and an UltrasonicSensor (A0):

In[10]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/be9d36a9-b566-45bb-943c-17b2c330e679"]

Publisher

M Braithwaite

Version History

  • 1.0.0 – 24 February 2020

Related Resources

License Information