Thursday, August 31, 2017

ATtiny85 Microcontroller - first impressions - excellent

For running motors etc from mobile phones I have been going "old school" analogue with early success with "robot rat" and having a lot of challenges with "robot snake". I had thought that a microcontroller approach would be complex and expensive. This is where the cellphone is the robot "brain" and with one or more microcontrollers as the "spinal cord". I found ATtiny85 boards selling for NZD 3.50, approx USD 2.30). I followed the instructions and everything worked, smoothly and easily. I had the first example program running on this ultra micro computer in 1 hour and I was running my own after another 20 mins.



Excellent instructions on how to program using the Arduino IDE:
https://digistump.com/wiki/digispark/tutorials/connecting

Only advice I would add is that I found it best to stop a program run by pulling out the USB cable and let ATtiny85 go dead for a few minutes while writing the next one - then plug in after starting the new program on the PC. The instructions suggest briefly pull it out and plug it in again when we  run a new program but that gave errors which went away when I did the longer disconnect.

I  am interested in using ATtiny85 to run hobby servos.
I run my first code "sketch" (see below)  - and it gives me 2 pieces of good news:

  1. the "delayMicroseconds()" method works on an ATtiny85
  2. although "delayMicroseconds()" specifies "unsigned int" as the data type, I found it was working OK with common ordinary "int".


int m = 16000;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(0, OUTPUT); //LED on Model B
  pinMode(1, OUTPUT); //LED on Model A  or Pro
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(0, HIGH);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(1, HIGH);
  //delay(200);
 
  delayMicroseconds(m);  
  delayMicroseconds(m);
  delayMicroseconds(m);
  delayMicroseconds(m);
  delayMicroseconds(m);
  delayMicroseconds(m);
 
  digitalWrite(0, LOW);    // turn the LED off by making the voltage LOW
  digitalWrite(1, LOW); 
  delay(3000);               // wait for 3 seconds
}

No comments:

Post a Comment