Use Haskell to program Arduino microcontrollers #Haskell #Arduino #Programming
Joey Hess posts about arduino-copilot – use Haskell to program an Arduino. It’s a FRP style system, and uses the Copilot DSL to generate embedded C code.
To make your arduino blink its LED, you only need 4 lines of Haskell:
main = arduino $ do
led =: blinking
delay =: constant 100
Running that Haskell program generates an Arduino sketch in an .ino file, which can be loaded into the Arduino IDE and uploaded to the Arduino the same as any other sketch. It’s also easy to use things like Arduino-Makefile to build and upload sketches generated by arduino-copilot.
I’m not the first person to use Copilot to program an Arduino. Anthony Cowley showed how to do it in Abstractions for the Functional Roboticist back in 2013. But he had to write a skeleton of C code around the C generated by Copilot. Among other features, arduino-copilot automates generating that C skeleton. So you don’t need to remember to enable GPIO pin 13 for output in the setup function; arduino-copilot sees you’re using the LED and does that for you.
Also: simulating an Arduino
One of Copilot’s features is it can interpret code, without needing to run it on the target platform. So the Arduino’s behavior can be simulated, without ever generating C code, right at the console!
Adafruit has had paid day off for voting for our team for years, if you need help getting that going for your organization, let us know – we can share how and why we did this as well as the good results. Here are some resources for voting by mail, voting in person, and some NY resources for our NY based teams as well. If there are additional resources to add, please let us know – adafruit.com/vote
Stop breadboarding and soldering – start making immediately! Adafruit’s Circuit Playground is jam-packed with LEDs, sensors, buttons, alligator clip pads and more. Build projects with Circuit Playground in a few minutes with the drag-and-drop MakeCode programming site, learn computer science using the CS Discoveries class on code.org, jump into CircuitPython to learn Python and hardware together, TinyGO, or even use the Arduino IDE. Circuit Playground Express is the newest and best Circuit Playground board, with support for CircuitPython, MakeCode, and Arduino. It has a powerful processor, 10 NeoPixels, mini speaker, InfraRed receive and transmit, two buttons, a switch, 14 alligator clip pads, and lots of sensors: capacitive touch, IR proximity, temperature, light, motion and sound. A whole wide world of electronics and coding is waiting for you, and it fits in the palm of your hand.