Posts

Sipping power... sleep modes and Swift for Arduino

Image
One feature I have been meaning to add to S4A for a while now is sleep.

It might not sound like an important feature but it could radically change the way projects are made.

A critical distinguishing feature of S4A is that it creates true native programs for the atmega328p microcontroller, meaning you don't need to have an Arduino UNO, plugged into your laptop or desktop via USB for these programs (although of course you can).

This sets it aside from many other attempts to simplify Arduino programming in the past, that effectively run programs on a full PC/Mac then send serial commands to the board to activate it.

The next step... how do you make a project that lives on batteries?

Well, right out of the box you can do that, at least for a while. See my Hallowe'en project from last year on this blog that I made for my daughter. But that lasted a couple of days on batteries before it faded. Anything with lots of lights and motors is going to need a lot of battery, of course. But…

Swift for Arduino newsletter - Saturday November 16th 2019

Hello to the Swift for Arduino community!


We are so excited to get in touch with you and let you know what's going on.
First and foremost... Black Friday/Cyber Monday!
We are giving away huge discounts!



*** The Swift for Arduino Starter Box... HALF PRICE!! *** (Contains a Seeed Studios Lotus board and connectors, you don't need any of your own hardware, get started right away!)
Note: to use this discount, you must enter the discount code BFCM50 in the Shopify store during checkout. This discount is limited in time and number - don't lose out!
Offer available from 00:00 on Friday 29th November, closes 23.59 on Monday 2nd December 2019
(For convenience, you can use this link:https://s4a-elements.com/discount/BFCM50?redirect=%2Fproducts%2Fcopy-of-s4a-silver-standard-box)



*** The Swift for Arduino IDE - license only... 70% OFF!! *** (suitable for customers who already have an Arduino UNO or similar board) This discount is automatic for customers purchasing the IDE only produc…

Grove PIR sensor

Image
As you can see in this video, I've hooked up a simple program to change the colour of a strip of neopixels in response to detecting people passing by.



See example code here: https://github.com/swiftforarduino/community/tree/master/work%20in%20progress/Grove%20Examples/Neopixel%20person%20sensor.swift4a

But this is an easy project to write.

Grove Temperature and Humidity sensor

Image
Grove are a fun concept, lots of cheap, little sensors, buttons, etc. on little PCBs with a universal 4 wire connector system (e.g. gnd, vcc, rx, tx or gnd, vcc, sda, scl). Making projects becomes more like lego but it's a bit less heavyweight than the "shields" or "hats" ideas, and a lot cheaper!

I got a mixed bag recently, about £12 worth, plus a "seeduino", which is Seeed Studios' *duino clone. The price quite recently dropped from something like $19 to something like $6.90! To be honest, most retailers, like the one I went to, are still selling nearer the old price, but I guess you can't blame them if that's what they paid for the stock. I think I forked out £18 in the end, plus the 12 for bits, making about 30... plus postage, etc.

I got:

An IR distance interrupter - single bit detects if a person (or thing) gets close, obviously great for robotics, although many other applications

PIR (passive IR) motion detector - security lights, e…

Button press daemon

As you've seen from my other posts, I have a couple of lamps at home, controlled by homekit. I also have a daemon on the pi that does (slightly inaccurate) PWM to control LEDs for showing the current weather forecast (look around my various blogs or ask here for links if you want to see how each of these works).

I've added a couple of useful functions to the daemon and recently upgraded it to be a bit more of a packaged service (see the github page). It's also in it's own repo now.

The last feature I added was I wanted some way to capture inputs not just output voltages.

There are already good solutions on the pi, many of them written in python, that will read input pin values, and about 7 years ago, someone patched the kernel to allow interrupt drive, an addition to sysfs to indicate you want to write code that blocks on a device with a poll() or select(). Probably the best solution for most people will be to use this mechanism within their own C program or (even bett…

Neopixel rainbow

Image
Thanks to great work by Mark Swanson, neopixel support is now available for S4A!
We needed a small upgrade to the S4A component library, AVR to give some timing functions, otherwise the work is all done in swift. You can see some great demo videos.

Spurred on by this I decided to add some optional extra low level support for many basic classes of neopixels, to give developers two options how to get started.

Here is an example of making a rainbow using the new "Fast iLED" components.

https://www.youtube.com/watch?v=e3nqyxCACKA&feature=youtu.be


And all this in just a few lines of simple Swift code!

import AVR
typealias IntegerLiteralType = UInt8let ledPin = 4
let pixels = 60var buffer = iLED_Setup_Buffered(pin: ledPin, count: pixels, hasWhiteChip: true)func rainbow() {
    let hueDeltaPerPixel = 255 / pixels
    for i in 0..<pixels {
        buffer[Int(i)] = iLEDFastMakeColor(hue: i &* hueDeltaPerPixel, saturation: 255, value: 255, white: 0)
    }
    iLEDFastWriteBuffer()
}

Halloween LED lights on a plastic trick or treat cauldron

Image
Halloween has past but it wasn’t uneventful. My two year old daughter went trick or treating for the first time and it was all so exciting!

When i saw the plastic cauldron she was carrying as a trick or treat bag i had an idea. I could use an arduino to operate red LEDs and make the cauldron flash on and off like little evil eyes. I knew she would love it!




Once I drilled the holes and got all the pieces I needed:

2 red LEDs soldered in series with a resistor.

I connected those to a breadboard arduino I had spare. (See my blog post on making a breadboard arduino.) You can just use a normal Arduino UNO here instead if you prefer. My reasons are because they're cheaper, and also because a breadboard Arduino uses less power and I wanted this to be battery powered.

I'm powering the whole thing with 3 AA batteries in a battery case. Because Maplin has shut down in the UK :((( I will have to wait for the battery holder to be delivered... no more weekend fun popping down the shop for …