Kuva Vasemmalla - Zoom

This week's assignment was to program the board we designed in an earlier week. To make it do something. On my board I designed to combine both the LED and the button to a single pin, to get 4 LEDs and 4 buttons.

Since I had 4 buttons to play with I tried to program something into all of them. But the button for the Orange LED was not co-operative. While the pin can lightup the LED it cant read the button state properly.

Original idea was to turn the board into a game of 'Simon says', where it randomly lights up LEDs and then waits player to push the buttons for them. But this proved difficult to do with one button out of commission. Not to mention having to wrap my head around the lower level code.

Originally I did try the Atmel Studio, and tried using the low level code for writing my program. I did manage to make a simple program for making the leds work when the button is pressed. Blinky I used the basic code examples in the documentation for my chip, and the examples for this weeks lecture details. The primary problem with the low level code, is that a week is simply not enough time, to learn to read the code enough to see the logic. No matter how many times you read through the documentation, unless you already master the low level programming, the code will be a cryptic mess.

Eventually I gave up on the Atmel Studio, and the low level programming, thus switched to the Arduino IDE. With this higher level code, it was easier to wrap my head around what I wanted the board to do so I was able to program the remaining buttons.

With the Arduino IDE, the website and tutorials were very useful in getting the code right. I already had some experience with Arduino so this was much more familiar ground for me, and finding solutions was easier. Mostly the code for the hello simon board is copypaste, and as such doesn't hold any special gimmicks.

Kuva Vasemmalla - Zoom

I did manage to brick one chip, and I had to replace it. I had set the fuses wrong, and when I had to set the fuses again I found in one of the example files for this week's assignment a note saying the 0x5E should be used for the chip for setting the chip to use the external clock I had on my board.

I needed to use command avrdude -cusbtiny -pt44 -Ulfuse:w:0x5e:m -Uhfuse:w:0cdf:m -Uefuse:w:0xff:m to set the fuses of my chip to make it use the external clock on the board.

Altough I have come to the conclusion that in the end, most of the times adding a clock is not really necessary, running the chip at internal 8Mhz is good enough.

Datasheet

For this weeks assignment most of the datasheet for the ATTiny44 chip was not of much use, and with the problems I had with the pins I had to look into the pin details of the chip.

To connect my buttons and leds I used the pins PA2, PA3, PA7, and PB2, of these the ones in the Port A, or the PA# ones were the ones that worked normally. After going through the documentation I understood that this was because they had the ADC, and PB2 did not. This meant PB2 could not be read or written to analogically.

Kuva Vasemmalla - Zoom

I figure if I pulled off the chip and soldered on one of my ATtiny841 chips, I could make the board work as intended. Because all pins have ADC and it has 8k of memory to work with.

At this time I have been expreimenting with using a raspberry pi zero for programming my boards, so while I used the arduino in my desktop to write the code, I finally used a raspi to program it. This does sound bit backwards I understand, but my goal has been to try to protect my computers from any problems possible design flaws with my boards could cause.

For now programming with the raspi is impractical because of its needs for existing proper hardware, like extra monitor, keyboard and mouse. So I wont continue developing the raspi hat further, besides in its current state it is properly functional.

Kuva Vasemmalla - Zoom

I like to use the AVRdude for programming the board, feels like the console interface gives me more control, than purely programming through Arduino. The reason I like to use the arduino for writing the program, is that the code is clear enough for me to see the logic. While the low level programming is powerful, it is much harder to see the logic in the code. Also with the chip properly defined, it is possible to export a ready to push hex file.

Once you have exported the file, you can just run the AVRdude to program it as is. For windows I like to use the stand alone version of the avrdude, meaning one just needs two files to run it.

avrdude -cusbtiny -p[ChipID] -Uflash:w:[programfile.hex]:i

With this command, I can push the hex of the program into the chip of the board. When programming with the raspi, and having its avrdude properly compiled, it would be just matter of moving the hex file to it for programming. Only real difference being the programmer would be set as -cgpio

The advantage of programming with the raspi zero, is mainly that if you have a bad board you fry only 5-10 bucks worth of hardware, but also that you dont have the chicken or the egg problem. You dont need to have programmed an ISP programmer, to program an ISP programmer. Thats why I called that project the AVR Origin.

Kuva Vasemmalla - Zoom

Personally I dont see any reason, for the labs to stick with the ATtiny44 chips. While low level programming is powerful, it provides no additional benefit to the course completion.

if you look at the pinout of the ATtiny 841 chip for example, its pins have a few features worth noting. They make it much more viable for the academy to use.

The ADC pins

These are good for gradual detection, a analog input, like a hall sensor for example. Giving you a value based on what voltage the sensor gives. The usual max value is 1024 with 10bit ADC, but it can vary from 256 for 8 bit ADCs to 65536 for 16 bit ADCs

The term ADC stands for Analog Digital Converter, meaning the pins can can convert analog signals to digital signals. It is possible to digital write to these pins to turn a led on or off

The PWM pins

The OC* pins, or the pins 5-10. These pins are for gradual driving of things, where the ADC pins are generally for reading in, these are for writing out with more control. You have 255 levels of output power to work with, by connecting a rgb led to three of these you can control the colour quite precisely. You can also control a servo motor with one of these pins. The control is done by dictating for how long the power is on. 255 is equal to power being on and 0 is equal to power being off.

The PCINT pins

These are for interruptive detection, where the adc pins are being constantly read, these are read only if an interrupt is attached to the pin. For example, reacting to button being pressed. AttachInterrupt lets you trigger different reactions, like different light shows with the board led's.

The XTAL pins

These pins are for connecting the external clock, most of the times for the purposes of this course an external clock is not really necessary, running the chip at high Mhz like recommended max of 16Mhz, can make communicating with the chip easier, because of how precise the external clock can be. When the 841 chip is given full 5 volts, people have found out that it is comfortable with even 20Mhz clock. With Atmel Studio's device programming tool you can simulate the chip and find the fuses you need for it. I have found that Efuse 0xFE, Hfuse 0xDF, and Lfuse 0xE2 gives me a functional internal clock at 8Mhz.

Serial interface

To these pins are the communications with the chip are connected to. MOSI, MISO, and SCL in addition of the reset pin, are the ones you need for programming the chip with the programming tool made earlier. For programming it with AVRdude you need to put this AVRdude addition into the avrdude.conf file.

TXD0 and RXD0, the ATtiny 841 has a hardware implementation of the serial communications, to these pins you can connect the FTDI connector. Just remember to make sure that the RXD pin needs to be connected to the TXD on the FTDI connector, this sounds backwards. But for comparison, TXD is your mouth, RXD is your ears. When you talk with someone, you dont listen with your mouth. This hardware implementation allows you to use the normal serial commands when using Arduino, this hardware implementation makes it much efficient to communicate with the board. ATtiny core library by Spence Konde lets you compile the program for it with arduino. You can access it by adding http://drazzy.com/package_drazzy.com_index.json To the arduino settings for Additional Boards Manager URLs

SCL and SDA, these pins are for the I2C networking interface. The 841 chip has hardware implementation of the slave service behind these pins, making the chip ideal for running slave boards in the I2C network. The master board on the I2C network should have the 5k Ohm pull up resistors for the SCL and SDA lines. WireS Library by Orangkucing is a direct drop in replacement for the arduino wire library, for using the ATtiny841 as a slave in I2C network.


I believe using a ATtiny841 chip in the future, will enable less computer literate people pass the course, as one doesnt have to have the mind of an engineer to grasp the low level programming needed. While still making full use of the chip and its capacities.

The paperwork

Sub-pages

Images List

  • FREEHTML5.co Free HTML5 Template
    Button 2

    When button 2 is pressed, the Orange and Red LEDs light up.

  • FREEHTML5.co Free HTML5 Template
    Button 3

    When 3rd button is pressed, the Blue and Green LEDs light up. The difference to default state is clear with the Blue LED.

  • FREEHTML5.co Free HTML5 Template
    Button 4

    When 4th button is pressed, the LEDs light up in order, or light up at the same time. Because the 1st button was not co-operative these two functions had to be tested on the same button.