7. Embedded programming

"read a microcontroller data sheet
program your board to do something"

We built and ISP and a hello_echo board. This week, it was time to program the board with the ISP. I think this week is important.
The first step is to connect the hello_echo board through the ISP with a USB port on the laptop. To make sure the pins were connected correctly, I looked at the schematics of the FabTiny* and the hello_echo board:

Then, opened Arduino application on the laptop. This is an IDE for Arduino's. The FABTiny* is Arduino compatible, so you can use this IDE. One thing that needs to be done, is install a hardware library, so that the Arduino application knows how to talk to the FABTiny*.
This tutorial on High-Low Tech was very useful in getting this to work. It provides a link to this repository on Github that holds ATtiny library that Arduino needs. After downloading the file, you need to move it to a '../hardware' directory in the Arduino documents folder (it automatically creates it in ~/Documents).
After running Arduino, under Tools>Boards, you will find an option for ATtiny. Here are te settings you need with the FABTiny*:


A tutorial about Make and Makefiles can be found here.
Now it is time to test if it all works correctly with a simple sketch like this one:

        int led_pin_1 = 7;

        void setup() 
        {
          pinMode(led_pin_1, OUTPUT);
        }

        void loop() 
        {
          digitalWrite(led_pin_1, HIGH);
          delay(2);
          digitalWrite(led_pin_1, LOW);
          delay(20);
        }

Yay! The LED is blinking.
note: What a great feeling to have built something, that controls something else that was also built by myself with a piece of code that I wrote. Yay!
Now it is time to experiment a little with the code. For instance, setting the LED to different intensities:
Controlling the LED with a button push. At first, the LED was operating inversely to my intention, untill I realized that the button pin is actually LOW when you push it :-).
After this I experimented a little with changing the LED blink speed with a push of the switch:

That's weird...

OK, so then things got interesting. I was witnessing fluctuations in my LED's intensity for no reason when I used this code:

analogWrite(led_pin, analogRead(button_pin));
First, I thought it was the code. That was not it.
Then, another theory I have (as of yet undetermined) is that the button pin is actually undefined when it is not pressed. On my board, the pin has no HIGH connection. So my guess is that when I ask the board to read the value on that pin in that case the signal is actually influenced by the circuit inside the ATtiny44 producing an unpredictable signal. My guess is that that is what I am seeing.
However... I am also seeing something else!
The (circuit, visible through the behaviour of the) LED seems to respond to my movements. When I move my hand towards the circuit (not moving or touching the circuit, my laptop, or anything else, the LED flickers. I thought the LED might be reacting to light, but I tested that with a flashlight and by turning the lights off which did not affect the behaviour, so I ruled that out.
Here is a wild guess, but I think the cable that connects the hello_echo board to the FABTiny* ISP is acting as an antenna. My guess is that that signal somehow finds itself onto the LED pin and is affected by my hand interfering with it's magnetic field.
I will add a link to a video of this.

Programming with c and the terminal

I managed to compile Neil's code from the terminal to the board. I will add pictures of that later.

Open items:

Some other things I still want to do with the board:

Learning points:

top of page