Monday 29 October 2018

Scaling up to mega, for some unknown reason

“10 square meters of heaven is worth far more than 100 square meters of hell.” 
Khang Kijarro Nguyen

Not to harp on too much about microcontrollers (but we will nonetheless), it seems that although most nerdy humanoids would be content with what is available in standard packages such as the Arduino Uno or Arduino Nano, we find ourselves once again drawing perilously close to the edge of insanity and playing with some freshly arrived Atmega128a chips.

They are lovely little things, about 14x14mm - and pack an impressive array of stats, including a whopping 128Kb of Flash, 4Kb of RAM and 4Kb of EEPROM. They are also dirt cheap, arriving from 中国 in a pack of 10 for just AUD $12.39. The bummer is they are damn small and not mounted in anyway useful for programming or deploying. So the first hurdle is soldering the chip onto a custom PCB adapter.


Steady hands and comically large magnifying glasses are the key
Courtesy of the Android App Magnifier on the trusty Nokia we were able to zoom in to check the final soldering for nasty shorting bridges.


Lovely connections between pins and tracks
The next problem was the actual programming. After hours of scouring the interwebs we found that we need to use a USBasp serial programmer and then upload ONLY using the menu "Sketch" and "Upload using Programmer".

Even then there was one last barrier, and that was that the otherwise marvelous MCUdude MegaCore was not able to recognise the normal pin designation of, for instance, PB0. So using the pin number instead (in this case 8 as shown below) worked fine, and then it blinked, and all was right with the world <sigh>.


The winding way to blinky success
The Nokia is also doing a great job of capturing the hilariously fuzzy and loud bumble bees that have recently reappeared after their winter hibernation. They aren't native, but they are a welcome addition to the garden this time of year.


Large, furry and cute
The raspberry patch is also teeming with bees at the moment, and so we are anticipating a magnificent crop for the jam cupboard, if they make it past the hands and mouths of the pickers - yum yum!



Saturday 27 October 2018

Advance to the past

Reading is what people did before YouTube, and I love retro stuff!
Toby Turner (Born: March 3, 1985)

An early Arduino board contained the Atmel Atmega8 chip. As posted previously, this has around one quarter of the grunt of a modern Arduino Uno R3, but we have been exploring these as replacement chips for the clock project in order to cut costs (not really true - the costs are minimal) but also as an intellectual exercise, because the chip is slightly brain dead by modern standards. Whenever you see links to work being done in this area the most common response is along the lines of "But why, it's an old crappy retro chip!"

It looked like our retro version was doomed when we couldn't get the chips to program, and we toasted a few into what seemed like oblivion with our BootLoader incompetence. So worried by their lack of response we ordered a high voltage chip re-fryer from Estonia (yet to arrive).

So after many pages of reading, and many hours of youtube (some of it about puppies - we got a little distracted at times) we have arrived at a solution that works for us! These are the steps that worked:
  1. Download the latest Arduino IDE
  2. Install the MiniCore from MCUdude (includes required bootloaders)
  3. Take out the Atmega328 chip and plug in an Atmega8
  4. Connect the "retro" Arduino to the computer firstly via a USBasp serial programmer
  5. Select options and burn bootloader as shown below
  6. Unplug the USBasp serial programmer and swap to the regular usb connector, selecting the following options, and program until you drop
Now we can restart the clock renewal project without the Frankenstein style wiring spaghetti that characterised programming the Atmega8 on a separate breadboard (including bent and broken pins from the constant shuffling to and from the programming shield). Nice!


Meanwhile the spring works goes on, and it seems that after mowing the lawn then retreating for a nice cup of tea just results in a time delay large enough that the lawn needs mowing again - so that's a bit of a pain!

Here is a nice pic of the dogs looking adoringly at Kym who is filling up one of the bath tubs that the sheep access for water.

Come back - we love you, we love you
Of course the worse thing to happen for the sheep would be a full grown puppy to use their newly refreshed water trough as a bath - right?

Isn't this the normal way to drink out of bath?
That cheeky girl gets away with so much - well, what's the point in being a puppy if you can't be just a little bit indulged from time to time.

It's a dog's life



Thursday 18 October 2018

Between the cool and the warm

“Earth's crammed with heaven, and every common bush afire with God.”
Elizabeth Barrett Browning

Sublime and breathtaking

Friday 12 October 2018

Eggsactly

"I tell you, the good old egg is the foundation of daily life. Stop the first man you meet in the street and ask him which he’d sooner lose, his egg or his wife, and see what he says!" 
P.G. Wodehouse

As promised, here are pics of our three new girls - April (spotty), May (large lady) and June (petite-ish lady). They are about a year old, and lay flawlessly white gorgeous eggs filled with golden orange goodness.  
April, May and June - nice ladies, good eggs
Speaking of three new girls - Karpov, Fisher and Tal were shorn today and look magnificent in just their undies, well, see for yourself. Our shearer Corey reckons they're rated 15/10 for condition (his polite way of saying they are a bit fat we think).
Bald ladies, no laughing or pointing
And also on the topic of good eggs, here is our grand-puppy Ella trying to crack one of the mysteries of life.


Oh well, it's a gallant first attempt.

I'll crack it next time, promise...



Sunday 7 October 2018

Grand Days Out

"And if the world went to hell in a hand-basket as it seemed to be doing, you could say good-bye to everyone and retreat to your land, hunkering down and living off it."
Jeannette Walls

The weekend can bring such joy! For instance one might receive from a neighbour fresh caught local trout. Then a sojourn into the wilderness to source three new girls for the coop (hello April, May and June - photos to follow). Further some wandering out among the orchard blossom and then a meal fit for the landed gentry.

Spot Kym on the balcony surveying her Queendom
Blossom now, cherry later!
All the local goodness on one plate

Interesting question from Oskar at the beach recently with our two dogs and one horse.

Dunno mate, just dunno...


Thursday 4 October 2018

Another day, another AVR

"Obsession is the wellspring of genius and madness."
Michel de Montaigne

The original clock project is about to receive a major overhaul. Firstly the code for that clock is a mess - it doesn't do interrupts at all well, so the user has to hilariously wait for a full cycle to complete before the clock wakes up when the slide switch for "set time" is toggled. This leads to a dreadful disquieting delay where you have to wonder if the little blighter is going to respond to a simple and necessary request.

The code overhaul also comes at a time (pun intended) when new chips have arrived from 中国 in deepest darkest Tasmania - the ATmega8. We believe it was the original chip used in the Arduino, followed by the ATmega168 and finally the ATmega328 which is what the clock project has used previously in a standalone version.

Why change chips? The ATmega328 is going up in price, currently around AU $19.01 for 10 pieces, whereas the ATmega8 in the same form factor is around AU $9.29 for the same quantity. The interesting (!) part of the revamp will be whether the new code will fit in a "smaller" chip - the ATmega328p has 32k RAM, 2048b SRAM and 1024b EEPROM, whereas the ATmega8 has "only" 8k RAM, 1024b SRAM and 512b EEPROM. Won't it be hilarious if the new code is too chunky to squeeze into that space? Although it is true that our recent dabbling in the dark arts of avr assembler might help shrink parts of the code.

The start of the project involved the usual ubiquitous "blinky" code (the AVR equivalent of "Hello World") - i.e. can we get any code to work on the Atmega8? Well within 5 minutes it seemed we had bricked the first chip whilst trying to burn a bootloader on the assumption that it didn't come from the factory with an installed bootloader. However, it did come with a bootloader and now wasn't talking at all.

Quite a few hours of reading and a fair bit of swearing over the next 3 days resulted in finding and following the definitive guide to ATmega8 bootloading (thanks ElectroNoobs), with just the one twist in the tail. We didn't want an external 16Mhz crystal oscillator driving the chip, but rather we would prefer the internal 8Mhz oscillator, since in the clock project the timing aspect is taken care of by an external DS3231 module. But we set up the oscillator anyway, just to establish lines of communication:


New bootloader installed and functioning
Following the resurrection after the requisite three days of uncertainty, the next step was to reload the bootloader via the avr isp programming shield and re-burn the chip with the appropriate settings (internal 8Mhz) as shown below:

So many options - but the 8Mhz is the key
Finally a little blinky magic and we are back in action.



But why always with the stupid blinky? Well, it's easy to establish if there is communication with such a simple program. It's visual if you don't have an oscilloscope, and timing is easy to check to see if the fuses have been set properly. Oh, and it's pretty.


So now onward to rewriting the clock code, but first a little relaxation and reflection with Oskar at Kingston Beach - noice!


Oskar seeks inspiration overlooking his temple



Wednesday 3 October 2018

Headlong into a fence

You'll reach into your wallet to brandish a photograph of a new puppy, and a friend will say, 'Oh, no - not pictures.'
Caroline Knapp

Yesterday at the park Kelly was chasing a ball (surprise) when she missed the visual cues relating to fencing wire and tried to grate herself. Ouch! So we have a cut tongue, lip and we are missing a bit of a tooth (again). You have to wonder at what point she will have at least a working knowledge of situational awareness?  She's fine (sort of), but my do we not need these heart in the mouth moments at our age. Look out soon for a photo of Kelly completely covered in tape and bubble wrap ready for her daily constitutional.

Ignore me at your peril
Speaking of pain and suffering - here is a link to three months of our lives as we recently revisited assembler programming using the attiny13A as inspiration. With a couple of overseas buddies cheering from the side, it has been a firkin of frustrating fun making the damn thing and we wish it well on it's voyage to publishing obscurity. Check this out:

    completetime:

        in r16, ADCSRA
        andi r16, 0b01000000
        ldi r17, 0b01000000
        eor r16, r17
        brbs 1, completetime
        in r16, ADCL
        in r17, ADCH 
        ldi r18, low(threshold)
        ldi r19, high(threshold)
        cp r16, r18
        cpc r17, r19
        brbc 2, ledon

Yikes! A well deserved lie down and a cool cloth on the forehead must surely be in order.