Reading thru the Datasheet, it shows plenty of information of the ATTINY85 which I used for the hello board.
The on-chip temperature sensor is selected by writing the code “1111” to the MUX[3:0] bits in ADMUX register when the ADC4 channel is used as an ADC input.
Previously on exercise 6, program our board using the Arduino and Arduino IDE. What we need are:
- USB Hub with optional power
- 2 x Mini USB cable
- 2 x 6 pin Female to Female cable
- 1 x FABISP
- 1 x HELLO BOARD (ATTINY 44/45)
- 1 x FTDI board
Here is a sample of how it looks like when including the FTDI board to communicate with the computer.
This week's assignment is similar to what we have done in week 6. Using it to display Blinking lights and Press button to turn on and off lights.
/* Blink Turns on an LED on for one second, then off for one second, repeatedly. Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to the correct LED pin independent of which board is used. If you want to know what pin the on-board LED is connected to on your Arduino model, check the Technical Specs of your board at https://www.arduino.cc/en/Main/Products This example code is in the public domain. modified 8 May 2014 by Scott Fitzgerald modified 2 Sep 2016 by Arturo Guadalupi modified 8 Sep 2016 by Colby Newman */ // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin LED_BUILTIN as an output. pinMode(PB1, OUTPUT); } // the loop function runs over and over again forever void loop() { digitalWrite(PB1, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(PB1, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second }
This is to define PB1 as an output.
void setup() { // initialize digital pin LED_BUILTIN as an output. pinMode(PB1, OUTPUT); }
// the loop function runs over and over again forever void loop() { digitalWrite(PB1, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(PB1, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second }
/* Button Turns on and off a light emitting diode(LED) connected to digital pin 13, when pressing a pushbutton attached to pin 2. The circuit: * LED attached from pin 13 to ground * pushbutton attached to pin 2 from +5V * 10K resistor attached to pin 2 from ground * Note: on most Arduinos there is already an LED on the board attached to pin 13. created 2005 by DojoDave <http://www.0j0.org> modified 30 Aug 2011 by Tom Igoe This example code is in the public domain. http://www.arduino.cc/en/Tutorial/Button */ // constants won't change. They're used here to // set pin numbers: const int buttonPin = PB0; // the number of the pushbutton pin const int ledPin = PB1; // the number of the LED pin // variables will change: int buttonState = 0; // variable for reading the pushbutton status void setup() { // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); // initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT); } void loop() { // read the state of the pushbutton value: buttonState = digitalRead(buttonPin); // check if the pushbutton is pressed. // if it is, the buttonState is HIGH: if (buttonState == HIGH) { // turn LED on: digitalWrite(ledPin, HIGH); } else { // turn LED off: digitalWrite(ledPin, LOW); } }
These are setting the global setting. But instead of using the pin name, I've used variable names for it to represent the Pin
const int buttonPin = PB0; // the number of the pushbutton pin const int ledPin = PB1; // the number of the LED pin // variables will change: int buttonState = 0; // variable for reading the pushbutton status
void setup() { // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); // initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT); }
void loop() { // read the state of the pushbutton value: buttonState = digitalRead(buttonPin); // check if the pushbutton is pressed. // if it is, the buttonState is HIGH: if (buttonState == HIGH) { // turn LED on: digitalWrite(ledPin, HIGH); } else { // turn LED off: digitalWrite(ledPin, LOW); } }
#include < SoftwareSerial.h> // constants won't change. They're used here to // set pin numbers: const int rx=PB3; // on ATTINY 85, RX is on PB3 const int tx=PB4; // on ATTINY 85, RX is on PB4 const int buttonPin = PB0; // the number of the pushbutton pin const int ledPin = PB1; // the number of the LED pin int val = 0; int old_val = 0; int state = 0; int flag = 0; SoftwareSerial mySerial(rx,tx); // variables will change: void setup() { mySerial.begin(9600); // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); // initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT); } void loop() { if(mySerial.available() > 0){ state = mySerial.read(); flag=0; } // read the state of the pushbutton value: val = digitalRead(buttonPin); // check if the pushbutton is pressed. // if it is, the buttonState is HIGH: // resets written counter to 0 if ((val == HIGH) && (old_val == LOW)) { state = 1 - state; flag = 0; delay(10); } old_val = val; if ((state == 1) && (flag == 0)) { digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level) mySerial.println("led is on!"); flag = 1; } else if ((state == 0) && (flag == 0)) { digitalWrite(ledPin, LOW); mySerial.println("led is off!"); flag = 1; } else { //do nothing } }
These are setting the global setting. But instead of using the pin name, I've used variable names for it to represent the Pin. And of course, we have to add a SoftwareSerial.h as it is required to show it on our Serial Monitor of Arduino IDE. I also added some variables as a flag or state to store the value. PB3 and PB4 are the RX and TX of the Attiny 85.
#include < SoftwareSerial.h> // constants won't change. They're used here to // set pin numbers: const int rx=PB3; // on ATTINY 85, RX is on PB3 const int tx=PB4; // on ATTINY 85, RX is on PB4 const int buttonPin = PB0; // the number of the pushbutton pin const int ledPin = PB1; // the number of the LED pin int val = 0; int old_val = 0; int state = 0; int flag = 0; SoftwareSerial mySerial(rx,tx); // variables will change:
void setup() { mySerial.begin(9600); // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); // initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT); }
void loop() { if(mySerial.available() > 0){ state = mySerial.read(); flag=0; } // read the state of the pushbutton value: val = digitalRead(buttonPin); // check if the pushbutton is pressed. // if it is, the buttonState is HIGH: // resets written counter to 0 if ((val == HIGH) && (old_val == LOW)) { state = 1 - state; flag = 0; delay(10); } old_val = val; if ((state == 1) && (flag == 0)) { digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level) mySerial.println("led is on!"); flag = 1; } else if ((state == 0) && (flag == 0)) { digitalWrite(ledPin, LOW); mySerial.println("led is off!"); flag = 1; } else { //do nothing } }3) In PuTTY, we set it as Serial communication, for my example, my FDTI board is in COM7, make sure the Speed is set to 9600
Check if the wiring is correct again, we can do this
you can check your wiring and that you installed both AVRDUDE and the driver correctly. Open a console and type
avrdude -c usbtiny -p t85 -n -v
avrdude -c usbtiny -p $(avrdevice) -U flash:w:$(SolutionName).hex