Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Mariano Martinez Peck
Mariano Martinez Peck

Posted on • Originally published atmarianopeck.wordpress.com on

     

Accessing Raspberry Pi GPIOs with Smalltalk

As I commented in anearlier post, one of the great featuresVASmalltalk has in the context of IoT, is a wrapper of the C librarypigpio which allows us to manage GPIOs as well as their associated protocols like 1-Wire, I2C, etc.

In this post we will see the basic setup for getting this to work.

Liquid error: internal

Setting up pigpio library

The first step is to install thepigpio C library. The easiest way is to install it with a packager manager if the library is available:

sudoapt-get updatesudoapt-getinstallpigpio
Enter fullscreen modeExit fullscreen mode

If you want a different version than the one installed by the packager manager or the package is not available, then you can compile it yourself:

rmmaster.zipsudo rm-rf pigpio-masterwget https://github.com/joan2937/pigpio/archive/master.zipunzip master.zipcdpigpio-mastermakesudomakeinstall
Enter fullscreen modeExit fullscreen mode

To verify the library is installed correctly, you can executepigpiod -v and that should print the installed version.

Setting up VASmalltalk

Inthis post I showed how to get a VASmalltalk ECAP release with ARM support. The instructions are as easy as uncompress the download zip into a desired folder.

The next step is to edit/raspberryPi/abt32.ini:

to include the following fields:

RaspberryGpio=libpigpio.soRaspberryGpioDaemon=libpigpiod_if2.soRaspberryGpioUltrasonicDaemon=libpigpioultrasonic.so
Enter fullscreen modeExit fullscreen mode

under the section[PlatformLibrary Name Mappings].

Then, fire up the VASmalltalk image by doing:

cdraspberryPi/./abt32.sh
Enter fullscreen modeExit fullscreen mode

Once inside VASmalltalk, go toTools ->Load/Unload Features… and load the featureVA: VAStGoodies.com Tools.

ThenTools ->Browse Configurations Maps, right click on the left pane (list of maps) and selectImport from VAStGoodies.com. That will import the selected version into the connected ENVY manager.

After that, on the same Configurations Map Browser, you must go toRaspberryHardwareInterfaceCore andRaspberryHardwareInterfaceTest, select the version you imported, right click and thenLoad With Required Maps.

You are done! You have installed pigpio library and the VASmalltalk wrapper. Let’s use it!

Some GPIO utilities to help you started

Before starting with VASmalltalk, let me show you some Linux utilities that are very useful when you are working with GPIO.

One of the commands ispinout which comes with Raspbian. It shows you everything you need to know about your Pi!! Hardware information as well as a layout of the pins:

And yes, do believe the command line output and visithttps://pinout.xyz. It is tremendously useful. A must have.

The other tool isgpio. This allows you to see the status of every pin and even pull up / down them right from there. Example below shows how to read all pins and then pull up BCM pin 17 (physical pin 11).

I don’t want to enter into the details in this post, but as you can see, each pin could have 3 different numbers: physical (the number on board), BCM and wPi (wiring Pi). And they also have a name. So…whenever you are connecting something you must be sure which “mode” they refer too. The number alone is not enough.

Managing GPIOs from Smalltalk!

In this post, we will see the most basic scenario of a GPIO which basically means pulling it up or down. When up, it outputs 3.3v (in the case of a Raspberry Pi), when down, 0. This is enough for you to play with LEDs, fans, and anything that doesn’t require “data” but just voltage.

The Smalltalk code for doing that is:

"This is an example of the VA tooling for accessing and dealing with the GPIOs.Instructions to run: 1) Make sure you have pigpio installed and that deamon is running. You can start it `sudo pigpiod` from a terminal.2) On a terminal, run `pinout` and identify GPIO17 (phisical pin 11) and the GROUND at phisical pin 14.3) Take a volt meter and put it in DCV 10 or 20. 4) Put the negative (usually black) cable into the ground (phisical pin 14) and the positive cable (usually red) into the GPIO17  (phisical pin 11). It should display 0V.5) Run below snipped of code which in fact turns on pin GPIO17 for output. 6) Repeat number 4) but now you should get a 3.3V output"| gpioInterface|[gpioInterface:=RaspberryGpioDaemonInterfaceraspberryGpioStart.gpioInterfacepinSetAsOutput:17;pin:17write:1.]ensure:[gpioInterfaceshutDown]
Enter fullscreen modeExit fullscreen mode

In the comment of above snippet you can see how you can validate that it actually worked… You can use a volt meter or usegpio readall to confirm the change. For the volt meter, set it in 10 / 20 volt (DCV) range. Then with the negative cable (usually black) touch any ground pin (for example, physical pin 6) and with the positive cable (usually red) touch GPIO pin 17 (physical pin 11). When the GPIO is on, then you should see the meter register about 3.3 volts and 0 when off.Welcome to the hardware debugger!

Conclusion

In this post you saw how to install pigpio C library, how to install the wrapper in VASmalltalk and see one basic example. In future posts we will see more advanced GPIO uses and protocols.

Liquid error: internal

Acknowledgments

The pigpio wrapper (RaspberryHardwareInterface) was a community pushed project. I think Tim Rowledge started with it in Squeak Smalltalk, then Louis LaBrunda started a port to VASmalltalk, and finallyInstantiations helped to get that port finished up and running.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Smalltalk developer and OOP evangelist. Interested in IoT, Edge Computing, Single Board Computers, Docker, etc. PhD in Computer Science.
  • Location
    Buenos Aires
  • Education
    PhD. Ing.
  • Work
    Full Stack Software Engineer at Instantiations Inc.
  • Joined

More fromMariano Martinez Peck

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp