This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
|
digispark:quickref [2014/02/07 15:22] digistump created |
digispark:quickref [2014/12/29 09:01] (current) joelparks bugfix result computation |
||
|---|---|---|---|
| Line 3: | Line 3: | ||
| - | GPIO output is 20 mA max, same as a regular Arduino. | + | * GPIO output is 20 mA max per pin, same as a regular Arduino. |
| - | + | * I2C pins are Pin 0 (I2C data/SDA) and Pin 2 (I2C clock/SCL). | |
| - | I2C pins are Pin 0 (I2C data/SDA) and Pin 2 (I2C clock/SCL). | + | * USB communication uses pins #3 and #4. Using these pins for your circuit can interfere with the USB interface, e.g. reprogramming the Digispark. So it’s a good idea to provide some sort of disconnect ability if you use either of these two pins. |
| - | + | * PWM output available on Pins 0, 1, 4. | |
| - | USB communication uses pins #3 and #4. Using these pins for your circuit can interfere with the USB interface, e.g. reprogramming the Digispark. So it’s a good idea to provide some sort of disconnect ability if you use either of these two pins. | + | * LED is on P1 for all Digispark labeled Rev2 or higher., P0 for those with no Rev label. |
| - | + | * All Rev3 Digisparks are counterfeit! (we never made a rev3) | |
| - | PWM output available on Pins 0, 1, 4. | + | * VIN pin takes 7-12v (6-32 may work but over 12 will probably need some heat sinking) and can output 500ma (but over 100-200 might need some heat sinking) |
| + | * 5V pin takes 4.5-5.5v (3v+ may work, but not supported) | ||
| + | * USB connector takes 5v (4.5-6v may work but not supported) | ||
| + | * Pin 3 has a 1.5K pull-up (for USB communications) | ||
| + | * Pin 5 has some limitations it cannot handle as much current is outputs more like 3.6v - but works fine for most non-current sourcing uses | ||
| + | |||
| + | **analogRead** | ||
| ADC (analog input/analogRead) pins are 2, 3, 4, and 5. Keep in mind that the digital pin numbers are ”’not”’ the same as the analog inputs! The printed labels on the Digispark are the ”digital” pin numbers. | ADC (analog input/analogRead) pins are 2, 3, 4, and 5. Keep in mind that the digital pin numbers are ”’not”’ the same as the analog inputs! The printed labels on the Digispark are the ”digital” pin numbers. | ||
| - | Digital 2 is analog (ADC channel) 1 | + | Digital 2 is analog (ADC channel) 1 |
| - | Digital 3 is analog (ADC channel) 3 | + | Digital 3 is analog (ADC channel) 3 |
| - | Digital 4 is analog (ADC channel) 2 | + | Digital 4 is analog (ADC channel) 2 |
| - | Digital 5 is analog (ADC channel) 0 | + | Digital 5 is analog (ADC channel) 0 |
| + | |||
| + | More detailed info here: http://digistump.com/wiki/digispark/tutorials/basics | ||
| Line 21: | Line 28: | ||
| Add this code to your sketch (outside of the loop and setup) and then call get_temp to get the temperature in C. Remember the internal temperature sensor is subject to the heat of the chip and not pre-calibrated. | Add this code to your sketch (outside of the loop and setup) and then call get_temp to get the temperature in C. Remember the internal temperature sensor is subject to the heat of the chip and not pre-calibrated. | ||
| - | [code] | + | int get_temp() { |
| - | int get_temp() { | + | analogReference(INTERNAL1V1); |
| - | analogReference(INTERNAL1V1); | + | int raw = analogRead(A0+15); |
| - | int raw = analogRead(A0+15); | + | /* Original code used a 13 deg adjustment. But based on my results, I didn't seem to need it. */ |
| - | /* 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 |
| - | // raw -= 13; // raw adjust = kelvin //this value is used to calibrate to your chip | + | int in_c = raw - 273; // celcius |
| - | int in_c = raw - 273; // celcius | + | analogReference(DEFAULT); |
| - | analogReference(DEFAULT); | + | return in_c; |
| - | return in_c; | + | } |
| - | } | + | |
| - | [/code] | + | |
| Line 38: | Line 43: | ||
| The following will display on the LCD the current voltage coming into the Digispark without having to use a pin to measure it! | The following will display on the LCD the current voltage coming into the Digispark without having to use a pin to measure it! | ||
| - | [code] | + | <code> |
| #include <TinyWireM.h> // I2C Master lib for ATTinys which use USI - comment this out to use with standard arduinos | #include <TinyWireM.h> // I2C Master lib for ATTinys which use USI - comment this out to use with standard arduinos | ||
| #include <LiquidCrystal_I2C.h> // for LCD w/ GPIO MODIFIED for the ATtiny85 | #include <LiquidCrystal_I2C.h> // for LCD w/ GPIO MODIFIED for the ATtiny85 | ||
| Line 98: | Line 103: | ||
| uint8_t high = ADCH; // unlocks both | uint8_t high = ADCH; // unlocks both | ||
| - | long result = (high<< | low; | + | long result = (high<<8) | low; |
| result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000 | result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000 | ||
| return result; // Vcc in millivolts | return result; // Vcc in millivolts | ||
| } | } | ||
| - | [/code] | + | </code> |