Programming ATtiny48

At this point, I would ask.
Could you make a schematic to show us how you pulled-down the pin, and how you try to connect it to Vcc pls

Yes, that's exactly my pinout.

I don't know how to do the schematic and sent it here but I placed a 10k resistance on the pin to the ground. Then, I'm just using a wire to connect the alimentation to the pin I'm trying to make HIGH.

Pen and paper... or photograph.

Upload button (box with "up arrow") in the edit messege box.

Could you try the Optiboot bootloader, and then the Digital instructions?

Still waiting for this...


The object code looks fine when I build it here:

void setup()
{
  DDRC |= (1 << PC0);   // pin as output
 122:	38 9a       	sbi	0x07, 0	; 7
/var/folders/gv/zn3wcml52jq0vvjnd95j8g6h0000gp/T/arduino_modified_sketch_646218/sketch_apr22a.ino:4
  DDRB &= ~(1 << PB0);  // pin as input
 124:	20 98       	cbi	0x04, 0	; 4
loop():
/var/folders/gv/zn3wcml52jq0vvjnd95j8g6h0000gp/T/arduino_modified_sketch_646218/sketch_apr22a.ino:9
}

void loop()
{
  if (PINB & (1 << PB0))      // When the pin is HIGH
 126:	18 9b       	sbis	0x03, 0	; 3
 128:	02 c0       	rjmp	.+4      	; 0x12e <main+0x50>
/var/folders/gv/zn3wcml52jq0vvjnd95j8g6h0000gp/T/arduino_modified_sketch_646218/sketch_apr22a.ino:11
  {
    PORTC |= (1 << PC0);      // LED  light
 12a:	40 9a       	sbi	0x08, 0	; 8
 12c:	fc cf       	rjmp	.-8      	; 0x126 <main+0x48>
/var/folders/gv/zn3wcml52jq0vvjnd95j8g6h0000gp/T/arduino_modified_sketch_646218/sketch_apr22a.ino:15
  }
  else
  {
    PORTC &= ~(1 << PC0);     // LED no light
 12e:	40 98       	cbi	0x08, 0	; 8
 130:	fa cf       	rjmp	.-12     	; 0x126 <main+0x48>

Seems contradictory to me. Did you write that complex code yourself? If not, please show the source. And the circuit.

I don’t have the 48 . But I was confused by ambiguity about the pin labels with the Tiny85.

Nothing complex? The hardest part is to understand how works the port but then writing this code is easy. Anyway, written by an AI or him doesn't change the fact that the code should work

Sorry, my post was meant for the OP, @thom11s, about his comment in post #49:

"No it’s not AI generated, I do have a 10k pull down on my inputs. I just don’t understand how to Read my inputs in that coding way. I’m not that knowing on that"

As a hobbyist, I'm challenged enough in writing sketches for the atTiny85, largely for the reason I gave. So coding direct manipulation of the port registers looks daunting to me.
:slightly_smiling_face:

The thread has apparently reached post #50 without resolving why your port manipulation code does not work with inputs. So I suggest focusing on why "...it never did anything."?

EDIT
Haven't seen your sketch or circuit for that attempt but one guess might be incorrect pinMode statements?

It's also a guess (I have no stats) but with more familiar code more of us might be able to contribute.

Meanwhile, with your ongoing register based approach, I'd suggest you get tightly in sync with @xfpd's post #53.

OP reports that the code that I use for testing in Post #10 "does not work" and stated "port access is the only way to make the input work," and the code in Post #10 barely lights the LEDs, and "nothing is able to read, and I have no Serial Monitor with Tiny48." The Wokwi setup I am using is in Post #34. It allows me to write "port access" or "high level functions" while using buttons (with pulldown resistors) and LEDs and the Serial Monitor. My guess is the confusion over Tiny48 pin number versus Px number (as with any pin-to-Px interpretation), coupled with "how to wire a pulling resistor."


That’s my set up. I’m measuring how much ampere is going inside of my LED, that's why there are a red wire on PC0 and a black one on my LED . I’m also connected to a power source sending 3V for the circuit. All of port B pins are connected with a 10K to ground.

1 Like


I'm only able to program the ATtiny48 with no bootloader. I'm also gonna put a picture of my Tools window so y'all can see what I'm doing.

I did try the code but it gave me that error :

C:\Users\thgau41\Desktop\Test2_ATtiny48\Test2_ATtiny48\Test2_ATtiny48.ino:27:2: error: exponent has no digits
12e: 40 98 cbi 0x08, 0 ; 8
^~~
C:\Users\thgau41\Desktop\Test2_ATtiny48\Test2_ATtiny48\Test2_ATtiny48.ino: In function 'void setup()':
C:\Users\thgau41\Desktop\Test2_ATtiny48\Test2_ATtiny48\Test2_ATtiny48.ino:4:5: error: expected ';' before ':' token
122: 38 9a sbi 0x07, 0 ; 7
^
C:\Users\thgau41\Desktop\Test2_ATtiny48\Test2_ATtiny48\Test2_ATtiny48.ino:5:2: error: 'var' was not declared in this scope
/var/folders/gv/zn3wcml52jq0vvjnd95j8g6h0000gp/T/arduino_modified_sketch_646218/sketch_apr22a.ino:4
^~~
C:\Users\thgau41\Desktop\Test2_ATtiny48\Test2_ATtiny48\Test2_ATtiny48.ino:5:6: error: 'folders' was not declared in this scope
/var/folders/gv/zn3wcml52jq0vvjnd95j8g6h0000gp/T/arduino_modified_sketch_646218/sketch_apr22a.ino:4
^~~~~~~
C:\Users\thgau41\Desktop\Test2_ATtiny48\Test2_ATtiny48\Test2_ATtiny48.ino:5:14: error: 'gv' was not declared in this scope
/var/folders/gv/zn3wcml52jq0vvjnd95j8g6h0000gp/T/arduino_modified_sketch_646218/sketch_apr22a.ino:4
^~
C:\Users\thgau41\Desktop\Test2_ATtiny48\Test2_ATtiny48\Test2_ATtiny48.ino:5:17: error: 'zn3wcml52jq0vvjnd95j8g6h0000gp' was not declared in this scope
/var/folders/gv/zn3wcml52jq0vvjnd95j8g6h0000gp/T/arduino_modified_sketch_646218/sketch_apr22a.ino:4
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\thgau41\Desktop\Test2_ATtiny48\Test2_ATtiny48\Test2_ATtiny48.ino:5:48: error: 'T' was not declared in this scope
/var/folders/gv/zn3wcml52jq0vvjnd95j8g6h0000gp/T/arduino_modified_sketch_646218/sketch_apr22a.ino:4
^
C:\Users\thgau41\Desktop\Test2_ATtiny48\Test2_ATtiny48\Test2_ATtiny48.ino:5:50: error: 'arduino_modified_sketch_646218' was not declared in this scope
/var/folders/gv/zn3wcml52jq0vvjnd95j8g6h0000gp/T/arduino_modified_sketch_646218/sketch_apr22a.ino:4
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\thgau41\Desktop\Test2_ATtiny48\Test2_ATtiny48\Test2_ATtiny48.ino:5:81: error: 'sketch_apr22a' was not declared in this scope
/var/folders/gv/zn3wcml52jq0vvjnd95j8g6h0000gp/T/arduino_modified_sketch_646218/sketch_apr22a.ino:4
^~~~~~~~~~~~~
C:\Users\thgau41\Desktop\Test2_ATtiny48\Test2_ATtiny48\Test2_ATtiny48.ino:7:5: error: expected ';' before ':' token
124: 20 98 cbi 0x04, 0 ; 4
^
C:\Users\thgau41\Desktop\Test2_ATtiny48\Test2_ATtiny48\Test2_ATtiny48.ino:8:1: error: expected ';' before 'loop'
loop():
^~~~
C:\Users\thgau41\Desktop\Test2_ATtiny48\Test2_ATtiny48\Test2_ATtiny48.ino: In function 'void loop()':
C:\Users\thgau41\Desktop\Test2_ATtiny48\Test2_ATtiny48\Test2_ATtiny48.ino:15:5: error: expected ';' before ':' token
126: 18 9b sbis 0x03, 0 ; 3
^
C:\Users\thgau41\Desktop\Test2_ATtiny48\Test2_ATtiny48\Test2_ATtiny48.ino:16:2: error: expected ';' before numeric constant
128: 02 c0 rjmp .+4 ; 0x12e <main+0x50>
^~~
C:\Users\thgau41\Desktop\Test2_ATtiny48\Test2_ATtiny48\Test2_ATtiny48.ino:16:44: error: 'main' was not declared in this scope
128: 02 c0 rjmp .+4 ; 0x12e <main+0x50>
^~~~
C:\Users\thgau41\Desktop\Test2_ATtiny48\Test2_ATtiny48\Test2_ATtiny48.ino:16:44: note: suggested alternative: 'min'
128: 02 c0 rjmp .+4 ; 0x12e <main+0x50>
^~~~
min
C:\Users\thgau41\Desktop\Test2_ATtiny48\Test2_ATtiny48\Test2_ATtiny48.ino:17:1: error: expected primary-expression before '/' token
/var/folders/gv/zn3wcml52jq0vvjnd95j8g6h0000gp/T/arduino_modified_sketch_646218/sketch_apr22a.ino:11
^
C:\Users\thgau41\Desktop\Test2_ATtiny48\Test2_ATtiny48\Test2_ATtiny48.ino:17:2: error: 'var' was not declared in this scope
/var/folders/gv/zn3wcml52jq0vvjnd95j8g6h0000gp/T/arduino_modified_sketch_646218/sketch_apr22a.ino:11
^~~
C:\Users\thgau41\Desktop\Test2_ATtiny48\Test2_ATtiny48\Test2_ATtiny48.ino:17:6: error: 'folders' was not declared in this scope
/var/folders/gv/zn3wcml52jq0vvjnd95j8g6h0000gp/T/arduino_modified_sketch_646218/sketch_apr22a.ino:11
^~~~~~~
C:\Users\thgau41\Desktop\Test2_ATtiny48\Test2_ATtiny48\Test2_ATtiny48.ino:17:14: error: 'gv' was not declared in this scope
/var/folders/gv/zn3wcml52jq0vvjnd95j8g6h0000gp/T/arduino_modified_sketch_646218/sketch_apr22a.ino:11
^~
C:\Users\thgau41\Desktop\Test2_ATtiny48\Test2_ATtiny48\Test2_ATtiny48.ino:17:17: error: 'zn3wcml52jq0vvjnd95j8g6h0000gp' was not declared in this scope
/var/folders/gv/zn3wcml52jq0vvjnd95j8g6h0000gp/T/arduino_modified_sketch_646218/sketch_apr22a.ino:11
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\thgau41\Desktop\Test2_ATtiny48\Test2_ATtiny48\Test2_ATtiny48.ino:17:48: error: 'T' was not declared in this scope
/var/folders/gv/zn3wcml52jq0vvjnd95j8g6h0000gp/T/arduino_modified_sketch_646218/sketch_apr22a.ino:11
^
C:\Users\thgau41\Desktop\Test2_ATtiny48\Test2_ATtiny48\Test2_ATtiny48.ino:17:50: error: 'arduino_modified_sketch_646218' was not declared in this scope
/var/folders/gv/zn3wcml52jq0vvjnd95j8g6h0000gp/T/arduino_modified_sketch_646218/sketch_apr22a.ino:11
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
C:\Users\thgau41\Desktop\Test2_ATtiny48\Test2_ATtiny48\Test2_ATtiny48.ino:17:81: error: 'sketch_apr22a' was not declared in this scope
/var/folders/gv/zn3wcml52jq0vvjnd95j8g6h0000gp/T/arduino_modified_sketch_646218/sketch_apr22a.ino:11
^~~~~~~~~~~~~
C:\Users\thgau41\Desktop\Test2_ATtiny48\Test2_ATtiny48\Test2_ATtiny48.ino:24:3: error: 'else' without a previous 'if'
else
^~~~
C:\Users\thgau41\Desktop\Test2_ATtiny48\Test2_ATtiny48\Test2_ATtiny48.ino:28:2: error: expected ';' before numeric constant
130: fa cf rjmp .-12 ; 0x126 <main+0x48>
^~~
C:\Users\thgau41\Desktop\Test2_ATtiny48\Test2_ATtiny48\Test2_ATtiny48.ino:28:53: error: expected primary-expression at end of input
130: fa cf rjmp .-12 ; 0x126 <main+0x48>
^
C:\Users\thgau41\Desktop\Test2_ATtiny48\Test2_ATtiny48\Test2_ATtiny48.ino:28:53: error: expected '}' at end of input
C:\Users\thgau41\Desktop\Test2_ATtiny48\Test2_ATtiny48\Test2_ATtiny48.ino:28:53: error: expected '}' at end of input
exit status 1

Compilation error: exponent has no digits

This code was not to test. It was to show that the compilation of your code in post#1 was correct.

BTW, @westfw, I'm interested, how did you get the object code pls?

Is that the aim of your project? To establish the current flowing through a (two colour?) LED?
Via a 270 ohm resistor (and an atTiny88 ouput pin) and 3.0 V supply?

Here, red consumes 3.8 ma and green 3.4 ma.

No, it's just to make sure the output is working, when i coded them using digitalWrite and pinMode, they only gave about 7uA. So I'm just keeping it there to be sure.

OK, understood - although your info does seem to come in fragments.

Re post #52, can you show us the sketch you used please. The one that "didn't do anything" if I recall.

About post #52, the code I'm referring to is done with the "usual" fonction (pinMode, digitalRead, digitalWrite). Those doesn't do anything. When I used them, none of my output worked.

Why is that?