Go Down

Topic: Digispark ATtiny85 micro USB module (Read 9215 times) previous topic - next topic

HermannSW

Dec 15, 2016, 12:22 am Last Edit: Dec 15, 2016, 12:34 am by HermannSW
Today I received my first Digispark ATtiny85 1$ modules (with micro USB connector, still waiting for Digispark kickstarter version -- that one can be inserted into Nanopi Neo or Orange Pi Zero USB connector directly).

Installation of board in Arduino IDE was easy following these instructions.

On first upload I ran into a well known problem, the sulution for I found in this digistump forum thread.

The blinking sketch is not named "Blink" but "Start", and I used it as basis for my first ATtiny85 "SOS" sketch:
https://www.youtube.com/watch?v=sl1cAjMZYp8
Code: [Select]
// http://morsecode.scphillips.com/morse.html

#define dt  100
#define di  { digitalWrite(1, HIGH); delay(dt); }
#define dit di
#define dah { digitalWrite(1, HIGH); delay(3*dt); }
#define _   { digitalWrite(1, LOW);  delay(dt); }
#define __  { digitalWrite(1, LOW);  delay(3*dt); }
#define ___ { digitalWrite(1, LOW);  delay(7*dt); }

void setup() {                
  pinMode(1, OUTPUT); //LED on Model A  or Pro
}

void loop() {
  di _ di _ dit __ dah _ dah _ dah __ di _ di _ dit ___
}


Hermann.
https://forum.arduino.cc/index.php?topic=462107.msg3236016#msg3236016
http://stamm-wilbrandt.de/en/Raspberry_camera.html

DrAzzy

Did you have a question?

As an aside, the way that #define is being (ab)used there is horrifying.
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

HermannSW

#2
Dec 15, 2016, 01:34 am Last Edit: Dec 15, 2016, 01:59 am by HermannSW
No  question, just wanted to post (positive) experiences with new ATtiny85 module.
I thought that "Microcontrollers" forum was best match for this.

The more I look into the Arduino IDE Digispark demos, the more I am impressed.
Only Due and Leonardo Arduinos support Keyboard library.
But 1$ ATtiny85 does support similar DigiKeyboard library!


Hermann.

https://forum.arduino.cc/index.php?topic=462107.msg3236016#msg3236016
http://stamm-wilbrandt.de/en/Raspberry_camera.html

dmjlambert

Yes, those are a little bit interesting.   I have a couple of them laying around, although I don't use them very often.   Beetles are about the same size but are the equivalent of a Leonardo.   They cost about $7.  Of course, they are 7 times more interesting...   :-)

HermannSW

For 7$ there is much more fun on the other side of the spectrum ;-)
[quad core 1.2GHz+USB+ethernet+wifi]
https://forum.arduino.cc/index.php?topic=462107.msg3236016#msg3236016
http://stamm-wilbrandt.de/en/Raspberry_camera.html

dmjlambert

That does look good, in a different category and larger size I suppose.   It reminds me of the Raspberry Pi Zero, except larger and more stuff on the board.

HermannSW

#6
Dec 17, 2016, 12:33 am Last Edit: Dec 17, 2016, 12:39 am by HermannSW
Took a while to find a TM1637 library that works with Digispark ATtiny85.
DigitalTube library does:
https://github.com/reeedstudio/libraries/tree/master/DigitalTube
https://www.youtube.com/watch?v=aUAacSjXYms

Hermann.
https://forum.arduino.cc/index.php?topic=462107.msg3236016#msg3236016
http://stamm-wilbrandt.de/en/Raspberry_camera.html

HermannSW

#7
Dec 20, 2016, 11:10 pm Last Edit: Dec 20, 2016, 11:22 pm by HermannSW
When installing Digispark ATtiny85 board in Arduino IDE you get quite some libraries ready to use.
"TinyRTClib.h" library allows to interface with DS3231 real time clock module (has accuracy of 5s/month).
The lipo is backed up by a CR2032 battery on DS3231 module.
Clock displays hh:mm for 2 seconds, then mm:ss for 5 seconds, and then repeats.
This definitely needs scrunch up in order to be used as wristwatch.
https://www.youtube.com/watch?v=nWZcf7Kr3Gw&feature=youtu.be

Code: [Select]
// "ATtiny85+TM1637+DS3231+H20 lipo" wristwatch v0.1
//
#include <TinyWireM.h>
#include "TinyRTClib.h"
#include "TM1637.h"

TM1637 tm1637(3 /*CLK*/, 4/*DIO*/);

RTC_DS1307 RTC;   // SDA=0, SCL=2

uint8_t h,l;
long last;
DateTime now;

void setup () {
  RTC.begin();

  if (! RTC.isrunning()) {
    while (true) {}
  }

  TinyWireM.begin();

  tm1637.init();
  tm1637.set(2);    //BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7;
  tm1637.point(1);

  last=RTC.now().unixtime();
}

void loop () {      // duration(1xRTC.now() plus display on TM1637) is <4ms
  do {
    now = RTC.now();
  } while (now.unixtime() == last);

  last = now.unixtime();

  h = (last%7 < 2) ? now.hour()   : now.minute();
  l = (last%7 < 2) ? now.minute() : now.second();
  
  tm1637.display(0,h/10);
  tm1637.display(1,h%10);
  tm1637.display(2,l/10);
  tm1637.display(3,l%10);
}


Hermann.
https://forum.arduino.cc/index.php?topic=462107.msg3236016#msg3236016
http://stamm-wilbrandt.de/en/Raspberry_camera.html

HermannSW

Today I wanted to program ATtiny85 with an old 2007 Eee PC, and wanted to try that with Arduino Create. But that was foredoomed by Create plugin being available for 64bit archictecture only.

OK, then I installed 1.8.0 IDE, added board and added the digispark.rule.

Programming ATtiny85 worked as before, but I was surprised on the "Eep!" message:
Code: [Select]
Running Digispark Uploader...
Plug in device now... (will timeout in 60 seconds)
> Please plug in the device ...
> Press CTRL+C to terminate the program.
> Device is found!
connecting: 16% complete
connecting: 22% complete
connecting: 28% complete
connecting: 33% complete
> Device has firmware version 1.6
> Available space for user applications: 6012 bytes
> Suggested sleep time between sending pages: 8ms
> Whole page count: 94  page size: 64
> Erase function sleep duration: 752ms
parsing: 50% complete
> Erasing the memory ...
erasing: 55% complete
erasing: 60% complete
erasing: 65% complete
>> Eep! Connection to device lost during erase! Not to worry
>> This happens on some computers - reconnecting...
>> Reconnected! Continuing upload sequence...
> Starting to upload ...
writing: 70% complete
writing: 75% complete
writing: 80% complete
> Starting the user app ...
running: 100% complete
>> Micronucleus done. Thank you!


Hermann.
https://forum.arduino.cc/index.php?topic=462107.msg3236016#msg3236016
http://stamm-wilbrandt.de/en/Raspberry_camera.html

HermannSW

Below is small sketch demonstrating 1/8/16 MHz processing for ATtiny85.
Slow Led flickering with 1, fast flickering with 8 and always on Led with 16 MHz.
Just select board "Digispark (Xmhz - No USB)" with X∈{1,8,16}.

Hermann.
Code: [Select]
void setup() {               
  pinMode(0, OUTPUT); //LED on Model B
  pinMode(1, OUTPUT); //LED on Model A  or Pro
}

int i;

void loop() {
  digitalWrite(0, HIGH);
  digitalWrite(1, HIGH);
  for(i=0; i<30000; ++i) {}
  digitalWrite(0, LOW);
  digitalWrite(1, LOW);
  for(i=0; i<30000; ++i) {}
}
https://forum.arduino.cc/index.php?topic=462107.msg3236016#msg3236016
http://stamm-wilbrandt.de/en/Raspberry_camera.html

HermannSW

#10
Dec 30, 2016, 11:41 pm Last Edit: Dec 30, 2016, 11:47 pm by HermannSW
Digispark quickref shows two functions, one to read the internal temparature sensor, and the other reading Digispark input voltage. The sketch uses a LCD to display.

I only have a Digispark ATtiny85 module and a USB cable currently, so made use of DigiKeyboard library as before.

I compiled below sketch, and when prompted to insert USB cable, I click into an empty gedit window first before inserting the USB cable with Digispark module. After the module has been flashed the sketch runs and gives temperature and voltage output in gedit window:
Code: [Select]
3C 4.89V
5C 4.89V
4C 4.89V
5C 4.89V
13C 4.87V
3C 4.89V
5C 4.89V
5C 4.89V
5C 4.87V
7C 4.89V
7C 4.89V
15C 4.87V
7C 4.89V
5C 4.89V
7C 4.89V
7C 4.89V
7C 4.89V
5C 4.89V
5C 4.87V
7C 4.87V
7C 4.87V
7C 4.89V
15C 4.87V
7C 4.87V
7C 4.87V
7C 4.89V
7C 4.89V


Internal temperature sensor shows 7°C working temperature.

Next I disconnected USB cable, opened a new empty gedit tab, inserted USB cable and pressed my thumb firmly on the ATtiny85. As you can see the internal temperature measured raises slowly up to 20°C:
Code: [Select]
7C 4.89V
9C 4.89V
9C 4.87V
9C 4.89V
9C 4.87V
11C 4.87V
11C 4.89V
11C 4.87V
11C 4.87V
11C 4.89V
11C 4.89V
11C 4.89V
19C 4.87V
11C 4.89V
11C 4.89V
11C 4.89V
11C 4.89V
13C 4.89V
11C 4.87V
11C 4.87V
11C 4.89V
13C 4.89V
11C 4.89V
13C 4.89V
13C 4.87V
13C 4.87V
13C 4.89V
11C 4.89V
13C 4.89V
13C 4.89V
13C 4.89V
13C 4.87V
13C 4.87V
13C 4.87V
13C 4.89V
13C 4.89V
13C 4.89V
13C 4.87V
13C 4.89V
13C 4.89V
13C 4.87V
13C 4.89V
13C 4.89V
13C 4.89V
13C 4.89V
13C 4.87V
15C 4.89V
15C 4.89V
13C 4.89V
13C 4.87V
15C 4.89V
13C 4.89V
13C 4.89V
13C 4.89V
13C 4.87V
13C 4.87V
15C 4.89V
13C 4.89V
13C 4.89V
13C 4.89V
15C 4.89V
13C 4.87V
13C 4.89V
15C 4.89V
15C 4.89V
23C 4.89V
15C 4.89V
15C 4.87V
15C 4.89V
13C 4.89V
13C 4.89V
23C 4.87V
15C 4.89V
15C 4.87V
15C 4.89V
15C 4.89V
13C 4.89V
23C 4.89V
15C 4.89V
15C 4.89V
15C 4.89V
15C 4.87V
15C 4.89V
23C 4.87V
15C 4.87V
15C 4.89V
15C 4.87V
15C 4.89V
15C 4.89V
15C 4.89V
15C 4.89V
15C 4.87V
15C 4.89V
15C 4.87V
15C 4.87V
15C 4.89V
15C 4.87V
15C 4.89V
15C 4.89V
15C 4.89V
15C 4.89V
15C 4.89V
15C 4.87V
15C 4.89V
15C 4.89V
15C 4.87V
15C 4.87V
15C 4.87V
15C 4.89V
15C 4.89V
15C 4.89V
15C 4.87V
15C 4.87V
15C 4.89V
15C 4.89V
15C 4.87V
15C 4.89V
15C 4.87V
15C 4.89V
15C 4.89V
15C 4.89V
15C 4.89V
15C 4.89V
15C 413C 4.89V
16C 4.87V
17C 4.87V
15C 4.87V
15C 4.87V
16C 4.87V
17C 4.87V
15C 4.89V
15C 4.89V
25C 4.89V
17C 4.89V
15C 4.87V
17C 4.89V
15C 4.87V
15C 4.87V
15C 4.87V
15C 4.89V
15C 4.89V
17C 4.89V
17C 4.87V
15C 4.87V
17C 4.87V
15C 4.87V
17C 4.87V
25C 4.87V
17C 4.87V
15C 4.89V
15C 4.87V
15C 4.87V
17C 4.87V
17C 4.87V
17C 4.87V
17C 4.89V
15C 4.87V
17C 4.89V
17C 4.87V
17C 4.89V
15C 4.89V
17C 4.87V
17C 4.87V
17C 4.87V
15C 4.87V
15C 4.87V
15C 4.87V
17C 4.87V
25C 4.87V
15C 4.89V
17C 4.87V
15C 4.89V
17C 4.89V
17C 4.87V
15C 4.89V
17C 4.87V
17C 4.87V
15C 4.87V
17C 4.87V
17C 4.89V
17C 4.87V
17C 4.89V
15C 4.87V
17C 4.87V
17C 4.87V
15C 4.87V
17C 4.89V
15C 4.89V
17C 4.89V
17C 4.89V
17C 4.89V
17C 4.87V
17C 4.87V
17C 4.89V
17C 4.87V
17C 4.89V
15C 4.89V
15C 4.89V
17C 4.87V
25C 4.85V
17C 4.87V
17C 4.87V
17C 4.87V
15C 4.87V
15C 4.85V
15C 4.83V
19C 4.81V
17C 4.85V
17C 4.85V
15C 4.85V
15C 4.83V
17C 4.85V
15C 4.85V
15C 4.85V
17C 4.85V
15C 4.85V
15C 4.85V
15C 4.85V
15C 4.85V
17C 4.85V
15C 4.83V
15C 4.83V
15C 4.85V
17C 4.85V
15C 4.85V
15C 4.83V
15C 4.85V
17C 4.85V
19C 4.81V
15C 4.83V
17C 4.85V
19C 4.81V
19C 4.81V
19C 4.81V
19C 4.79V
19C 4.81V
19C 4.81V
19C 4.81V
19C 4.81V
15C 4.83V
19C 4.81V
19C 4.81V
19C 4.81V
19C 4.79V
19C 4.81V
19C 4.81V
19C 4.81V
19C 4.79V
21C 4.77V
19C 4.81V

 

Using gedit window for Digispark output display is not perfect, but works for easy cases.

Hermann.
Code: [Select]
#include <TinyWireM.h>
#include "DigiKeyboard.h"

void setup()
{
  TinyWireM.begin();  // initialize I2C lib
  DigiKeyboard.sendKeyStroke(0);
  delay(1000);
}

void loop()
{
  //read and convert the voltage to a decimal
  long voltage = readVcc();
  double decimalVoltage = doubleMap(double(voltage),0,6000,0,6);

  DigiKeyboard.print(get_temp());  
  DigiKeyboard.print("C ");
  
  DigiKeyboard.print(decimalVoltage);  
  DigiKeyboard.println("V ");
  
  // delay so this updates approximately 4 times per second
  delay(250);
}

double doubleMap(double x, double in_min, double in_max, double out_min, double out_max)
{
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

long readVcc() {
  // Read 1.1V reference against AVcc
  // set the reference to Vcc and the measurement to the internal 1.1V reference
  #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
    ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
    ADMUX = _BV(MUX5) | _BV(MUX0);
  #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
    ADMUX = _BV(MUX3) | _BV(MUX2);
  #else
    ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  #endif  
 
  delay(2); // Wait for Vref to settle
  ADCSRA |= _BV(ADSC); // Start conversion
  while (bit_is_set(ADCSRA,ADSC)); // measuring
 
  uint8_t low  = ADCL; // must read ADCL first - it then locks ADCH  
  uint8_t high = ADCH; // unlocks both
 
  long result = (high<<8) | low;
 
  result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000
  return result; // Vcc in millivolts
}

int get_temp() {
  analogReference(INTERNAL1V1);
  int raw = analogRead(A0+15);
  /* Original code used a 13 deg adjustment. But based on my results, I didn't seem to need it. */
  // raw -= 13; // raw adjust = kelvin //this value is used to calibrate to your chip
  int in_c = raw - 273; // celcius
  analogReference(DEFAULT);
  return in_c;
}
https://forum.arduino.cc/index.php?topic=462107.msg3236016#msg3236016
http://stamm-wilbrandt.de/en/Raspberry_camera.html

HermannSW

The other Digispark ATTiny85 1$ module can be powered & programmed without any cables.

I played with ATTiny85 generating PWM and used 5$ 24Msps logic analyzer to vizualize:


This is the pattern I generated, PWM frequency is 1Khz:


This was the sketch I used, based on cool Technoblogy Four PWM Outputs from the ATtiny85 posting:
Code: [Select]
// Based on "Three PWM Outputs"
// http://www.technoblogy.com/show?LE0
//
volatile uint8_t* Port[] = {&OCR0A, &OCR0B, &OCR1B};
int Pin[] = {0, 1, 4};

void setup() {
  pinMode(Pin[0], OUTPUT);
  pinMode(Pin[1], OUTPUT);
  pinMode(Pin[2], OUTPUT);
  // Configure counter/timer0 for fast PWM on PB0 and PB1
  TCCR0A = 3<<COM0A0 | 3<<COM0B0 | 3<<WGM00;
  TCCR0B = 0<<WGM02 | 3<<CS00; // Optional; already set
  // Configure counter/timer1 for fast PWM on PB4
  GTCCR = 1<<PWM1B | 3<<COM1B0;
  TCCR1 = 3<<COM1A0 | 7<<CS10;
}

void loop() {
  for (int i=0; i <= 255; i+=15) {
    *Port[2] = 255-i;  // Pin[2]==4
    delay(1);
  }
}


Hermann.
https://forum.arduino.cc/index.php?topic=462107.msg3236016#msg3236016
http://stamm-wilbrandt.de/en/Raspberry_camera.html

HermannSW

Today I combined my Arduino pan/tilt system from last year with Raspberry camera and my new PiZeroW (Pi Zero wireless, 11.70$, available since a week):
https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=176788


The bill of material for the Arduino pan/tilt part was 7$ with free shipping. The biggest part was with 3$ the Arduino Uno used. Now I replaced that with 1$ ATTiny85 and it works. This drops "Arduino pan/tilt system for Raspberry camera" to 5$ in total ! Here is the complete setup, just the Uno replaced by ATTiny85 (click on photos for more details):


This is just the ATTiny85 with two mini breadboards:


The 6th pin P5 does not fit onto the 5 row mini breadboard, but P0-P4 do.

The sketch had to be modified a bit
  • include <SoftRcPulseOut.h> instead of <Servo.h>
  • add SoftRcPulseOut::refresh(NOW) after 20ms delay

But that is all that's needed, here is the compete sketch:
Code: [Select]
#include <SoftRcPulseOut.h>
 
SoftRcPulseOut myservo1, myservo2;
#define NOW 1

int potpin1 = A1, potpin2 = A2;
int val1,val2;

void setup() {
  myservo1.attach(1);
  myservo2.attach(0);
}

void loop() {
  val1 = map(analogRead(potpin1), 0, 1023, 0, 180);
  val2 = map(analogRead(potpin2), 0, 1023, 0, 180);
  myservo1.write(val1);
  myservo2.write(val2);
  delay(20);
  SoftRcPulseOut::refresh(NOW);
}


This is the first really useful application I did with ATTiny85, the core of pan/tilt system.

Hermann.
https://forum.arduino.cc/index.php?topic=462107.msg3236016#msg3236016
http://stamm-wilbrandt.de/en/Raspberry_camera.html

CatDadJynx

Just wanted to say thanks for this thread- bought one of these a while back and couldn't find the board drivers, for some reason... this is all super helpful, thanks!

Go Up