Posts

Showing posts from August, 2018

Measuring fan RPM

Image
Going on from our earlier posts about how to synchronise a strobe light to a three wire fan, I've designed something a bit more practical, to measure the RPM of the fan. https://github.com/swiftforarduino/community/blob/master/contributed%20examples/Fan%20RPM%20speed.swift4a/main.swift The important trick is we need to turn one of the timers into a "counter" and count the number of pulses coming in from the fan tachometer.  Then if we monitor the count per unit time, we get the RPM simply by multiplication. What is a timer really? It is actually really a counter.  In normal timer modes, the timer counts clock cycles. You may have noticed you can run it at different speeds, this is done by dividing the clock cycle. But alternatively, two of the atmega328p timers can alternatively count pulses from external sources. How easy is it to do? Well on S4A it's pretty easy... timer0SetAsCounter(edgeType: RISING_EDGE) Timer 0 will now count the rising edge of pulses

The internal Arduino temperature sensor...

Image
OK so I've probably already surprised many of you.  Didn't know there's a temperature sensor built into an arduino? Regular readers will be familiar with the chip in the Arduino UNO, the basis of the Swift for Arduino product, being the Atmel Atmega328p. This contains an internal temperature sensor that's hooked up to the same MUX that feeds the analog to digital converter, that allows you to read analog voltages on pins A0-A5.  In practical terms, that means you can read the temperature from this sensor and by extension roughly the temperature of the arduino by programming it correctly. On some platforms this would be a complex process, on S4A... not so much... Here's the code... let temperature = slowReadTemperatureCentigrade(tsOffset: 335, tsGain: 1.15) Yup.  That's it! What are the magic numbers for? What are the caveats? Why can't I do this on other Arduino platforms or why is it so difficult?? Well, the magic numbers and the caveats... I&

Using a rotary encoder... fast to code fast to run... Swift!

Using a rotary encoder... fast to code fast to run... Swift! If you’ve ever written code for handling a rotary encoder before in another microcontroller IDE you’ll know it can be... complex. A rotary encoder is the fancy name for one of those dials that can turn endlessly, unlike a potentiometer or rheostat. Think of the “jog wheels” on some DVD players. They’re really cool but the code to handle them can be tricky. They give you two pins that turn on and off in a specific sequence depending if turned clockwise or counter clockwise (anti clockwise if you’re British). So to code you need to know the current state of both pins and the previous stare of both pins and see what changed. From which there are about 9 possibilities, one being “no change” then 4 changes that indicate a turn one way and four that indicate a turn the other way. Does that sound like a switch statement in Swift? It sure does! Look at this code!...   let currentPinState = (digitalRead(pin: pin1), digit

Fun with power supplies and powering an UNO

Fun with power supplies and powering an UNO: One of the best bits about becoming an amateur EE is playing with the kit. :) Here's some of the fun and useful stuff I've been learning to do. I didn't learn this off anyone, I just came up with it so it might be daft or dumb. Apologies. Firstly, I used my bench power supply to figure out how to improve the process of powering an Arduino (or just a free standing atmel chip/breadboarduino) from the same power source as the rest of your project: Part 1 (the main part): https://www.youtube.com/watch?v=5XmIFeMi_RI Part 2 (the addendum): https://www.youtube.com/watch?v=XlMpim2aHy0 And another trick. How quickly testing my LEDs with a bench PSU: https://www.youtube.com/watch?v=SrGYIpvkWdc

Syncing a strobe to a fan, fun, Swift and easy!

Syncing a strobe to a fan, fun, Swift and easy! Have you ever really looked at a PC fan?  I must admit I hadn't really until recently. I knew that from linux boxes you could often control the speed of at least some of the fans and even measure the speed of the fans sometimes.  I also knew you could get little side fans that just plugged into the same, regular 4-pin power cables that snake all over the inside of your typical desktop, powering CD-ROM drives (haha, just kidding), HDs, etc. all over the inside. Yet the more controlled types of fans seemed to have their own special connectors on a motherboard. It turns out that fans come in (at least) three varieties... Simple "two wire" fans that have a power and ground rail wire - these usually cannot be speed controlled or measured. Three wire fans - it turns out these can have their speed measured and possibly controlled. Four wire fans - these have easy speed control and speed measure. I've not done an au