I am using arduino ide v1.8.9 version.
I am reading analog value frm 20k potentiometer. I am using arduini uno isp as programmer. I wanted to print analogread value particular pin and display count on uart. Is there way to print count values for analogread for attiny10. If yes kindly let me know step.
I tried serial.begin() and serial.println. it wont work on attiny10 mcu. It work on arduino uno.
Attiny10 has no UART, so has no serial.
How we can know the count value in that case. Since we cant debug the code. Reversly i can do. But may not get exCt count value when read
I found that with a little tweaking you can use this library to debug with serial from an Attiny10 (I am using attiny10core ).
Install that library manually in your libraries folder.
edit the file debugSerial.h
change
inline void dprints_p(const __FlashStringHelper* s)
into:
inline void dprints_p(const char* s)
and change
void print(const __FlashStringHelper* str) { dprints_p(str); }
into
void print(const char* str) { dprints_p(str); }
You also need to make some small edits in the example. This example works.
/* debugSerial example
* Ralph Doncaster [nerdralph] 2020 MIT Licence open source
*/
// default extra wait = 1 cycle (8 cycles/bit total)
// valid range = 0-3 cycles, for a total of 7-10 cycles/bit
// #define DTXWAIT 1
// default TX GPIO = PB0
// #define DBG_TX B,0
#include <debugSerial.h>
#include <avr/delay.h>
debugSerial dSerial;
void setup() {}
void loop()
{
uint8_t count = 0;
while (1) {
dSerial.print("count: ");
dSerial.print(count);
dSerial.print(" 0x");
dSerial.println(count++, dSerial.Base16);
_delay_ms(1000);
}
}
This is the output you will get on PB0 with a fixed baudrate of 1000000, when you compile the Attiny10 at 8MHz
Then how to connect PB0-pin to the USB Port of the PC?
How to install the referred attiny10core?
FTDI or any other USB<>Serial adapter
Via boards manager installation.
For programming the ATtiny10/9/5/4.
I have followed the instructions of the referred GitHub; unfortunately, I could not install the core as Attiny10 does not appear on the Librray Manager window after I have typed it in the filter box.
GolamMostafa:
Librray Manager
you need to search in >>>>>>> Boards Manager <<<<<<<<<
1 Like
Thank you. I have got the core and have installed it.
@hmeijdam
After installing the ATtiny10Core, my ATTinyCore has disappeard from the Boards List of the IDE. How can I recover that? Is it possible that I get the both boards listed in the IDE?
Most likely you have overwritten your AttinyCore JSON file with the one for attiny10core
You need both of them in your list with additional boards
http://www.technoblogy.com/package_technoblogy_index.json
and
http://drazzy.com/package_drazzy.com_index.json
Thank you. I have now got both.
@hmeijdam
Need small help . Here is code i am writing everything fine . I am using 20k pot to get count value and DIP for timing adjustment.
I am facing issue with below
Getting correct count adjust the ranges.
Timing. For example if 1min set . relay turn on at 50Sec . similarly 10Sec difference when 2 min to 10mins.
I have 30 division 3sub division = 1range.
I.e means 1 to 2 select range i have 2 division.
Can you help me out here.
#include <avr/io.h>
#include <avr/interrupt.h>
#define F_CPU 8000000UL
#include <util/delay.h>
#include <stdint.h>
// ADC channel definitions
#define POT_CHANNEL 0
#define DIP_CHANNEL 1
#define DIP4_CHANNEL 3
// Digital pin definitions
#define RELAY_PIN 2
#define DELAY_0_1MS 1 // 0.1 milliseconds
#define DELAY_1MS 1 // 1 millisecond
#define DELAY_100MS 100
#define DELAY_0_1SEC 100 // 100 milliseconds
#define DELAY_10MS 10
// Delay constants (in milliseconds)
#define DELAY_1SEC 1000
#define DELAY_10SEC 10000
#define DELAY_30SEC 30000
#define DELAY_1MIN 60000
#define DELAY_3SEC 3000
#define DELAY_3MIN 180000
#define DELAY_10MIN 600000
#define DELAY_30MIN 1800000
#define DELAY_1HR 3600000
#define DELAY_3HR 10800000
#define DELAY_10HR 36000000 // Added delay for 10 hours
#define DELAY_30HR 108000000
void InitADC(uint8_t channel) {
ADMUX = (ADMUX & 0xF0) | (channel & 0x0F);
ADCSRA = (1 << ADEN) | (1 << ADPS1) | (1 << ADPS0);
}
uint16_t ReadADC(uint8_t channel) {
ADMUX = (ADMUX & 0xF0) | (channel & 0x0F);
ADCSRA |= (1 << ADSC);
while (ADCSRA & (1 << ADSC));
return ADCL;
}
void InitIO() {
InitADC(POT_CHANNEL);
InitADC(DIP_CHANNEL);
InitADC(DIP4_CHANNEL);
DIDR0 = (1 << ADC0D) | (1 << ADC1D); // Disable digital input buffers for ADC pins
DDRB |= (1 << RELAY_PIN); // Set RELAY_PIN as output (Relay)
}
void RelayOn() {
PORTB |= (1 << RELAY_PIN); // Set RELAY_PIN high
}
void RelayOff() {
PORTB &= ~(1 << RELAY_PIN); // Set RELAY_PIN low
}
uint32_t getBaseDelay(uint16_t dipValue, uint8_t dip4State) {
if (dipValue <= 40) return (dip4State == 1) ? DELAY_1SEC : DELAY_1MIN;
if (dipValue <= 50) return DELAY_1HR;
if (dipValue <= 130) return (dip4State == 1) ? DELAY_10SEC : DELAY_10MIN;
if (dipValue <= 160) return DELAY_10HR;
if (dipValue <= 180) return (dip4State == 1) ? DELAY_3SEC : DELAY_3MIN;
if (dipValue <= 210) return DELAY_3HR;
if (dipValue <= 230) return (dip4State == 1) ? DELAY_30SEC : DELAY_30MIN;
return DELAY_30HR;
}
uint8_t MapPotentiometer(uint8_t adcValue) {
if (adcValue >= 240) return 1;
if (adcValue >= 220) return 2;
if (adcValue >= 200) return 3;
if (adcValue >= 180) return 4;
if (adcValue >= 160) return 5;
if (adcValue >= 140) return 6;
if (adcValue >= 120) return 7;
if (adcValue >= 100) return 8;
if (adcValue >= 80) return 9;
if (adcValue >= 60) return 10;
if (adcValue >= 50) return 11;
if (adcValue >= 40) return 12;
if (adcValue >= 30) return 13;
if (adcValue >= 20) return 14;
if (adcValue >= 10) return 15;
return 16;
}
uint32_t ReadDIPSwitch() {
uint8_t dip4State = (ReadADC(DIP4_CHANNEL) < 100) ? 1 : 0;
uint16_t dipValue = ReadADC(DIP_CHANNEL);
return getBaseDelay(dipValue, dip4State);
}
void DelayTime(long milliseconds) {
delay(milliseconds); // Use delay function for runtime delays
}
int main() {
InitIO();
RelayOff();
uint32_t timeValue;
uint8_t potValue;
uint32_t adjustment = 0;
while (1) {
for(uint8_t i=0;i<100;i++)
{
potValue = ReadADC(POT_CHANNEL);
}
uint8_t range = MapPotentiometer(potValue);
uint32_t TimeSection = ReadDIPSwitch();
timeValue = (TimeSection * range)/10;
DelayTime(timeValue);
RelayOn();
}
}
i have mentioned voltage coming across the Analog pin 1
uint32_t getBaseDelay(uint16_t DIP_Value, uint8_t DIP4_state) {
if (DIP_Value <= 20) { // Assume voltage below ~0.39V
return (DIP4_state == 1) ? DELAY_1SEC : DELAY_1MIN;
} else if (DIP_Value <= 50) { // Assume voltage around ~0.98V
return DELAY_1HR;
} else if (DIP_Value <= 130) { // Assume voltage around ~2.55V
return (DIP4_state == 01) ? DELAY_10SEC : DELAY_10MIN;
} else if (DIP_Value <= 160) { // Assume voltage around ~3.14V
return DELAY_10HR;
} else if (DIP_Value <= 180) { // Assume voltage around ~3.53V
return (DIP4_state == 01) ? DELAY_3SEC : DELAY_3MIN;
} else if (DIP_Value <= 210) { // Assume voltage around ~4.12V
return DELAY_3HR;
} else if (DIP_Value <= 230) { // Assume voltage around ~4.5V
return (DIP4_state == 01) ? DELAY_30SEC : DELAY_30MIN;
} else if (DIP_Value <= 255) { // Assume voltage around ~5.0V
return DELAY_30HR;
}
return DELAY_1SEC; // Default delay
}