-2
\$\begingroup\$

I have some knowledge about Arduino, but it's my first time using solo microcontrollers and this sort of thing, i have no idea of what i should do in this case.

I'm following a guide that users ATTiny13 with a Led and an LDR sensor, but i don't have that microcontroller, so i'm using a ATmega328P-PU, which has a slightly different pinout.

I searched a lot and found many important stuff, but i can't figure out what to do here.

The project i'm doing uses this guide.

The code is commented with the three pins: LDR sensor, LED and some other pin with a resistor, or something like that.

// use PB2 for led, pin 7
#define LED_BIT 2
// use PB3 to enable ldr, pin 2
#define ADC_ENA_BIT 3
// use ADC2, PB4, pin 3
#define CHANNEL 2

The ATmega datasheet shows PB, PC and PD pins, but ATtiny has only PB, i don't know what i should do and which ports are equal to each other.

Basically, i need to know which pins on ATmega i should use as an alternative to the ones on ATtiny13 in the code.

\$\endgroup\$
  • 1
    \$\begingroup\$ You do realize you'll need to change the entire code too, right? You can't take code written for one uC and expect it to run directly on a completely different one \$\endgroup\$ – DerStrom8 Sep 16 '15 at 19:18
  • 1
    \$\begingroup\$ If the program uses Port B (PB), then you may as well use Port B on the ATMega, but you could use any port or pins, as long as you change the code to suit. I don't know if the ATTiny and ATMega are code-compatible. If not, you may have to make some software changes to make the code compile for the ATMega. \$\endgroup\$ – Peter Bennett Sep 16 '15 at 19:43
  • 1
    \$\begingroup\$ @derstrom8 the changes between a tiny and a mega for simple code would be minimal, mostly just pin/port changes for the most part. In this case, I dont even think the ADC code needs much changes tbh. \$\endgroup\$ – Passerby Sep 17 '15 at 4:06
  • \$\begingroup\$ Thanks @Passerby. I was not sure how the two uCs differed. In my experience with other micros the code has to be changed completely. If the registers are similar, though, I expect it would require less effort \$\endgroup\$ – DerStrom8 Sep 17 '15 at 15:50
  • \$\begingroup\$ @derstrom8 actually, i didn't until i read the above answers. As i said, i'm totally new to this. PeterBennett thanks for the help. In general, i think i'll switch to the suggested microcontroller, since it's cheaper, easier and a lot simpler to use. Thank you all. \$\endgroup\$ – George Sep 17 '15 at 16:02
1
\$\begingroup\$

Well you will have to change your complete code according to your MCU, not the complete code but yes few things.

You can use PB5 for you ADC channel. PB2 for enable and PB1 for led.

\$\endgroup\$
0
\$\begingroup\$

I'm following a guide that users ATTiny13 with a Led and an LDR sensor, but i don't have that microcontroller, so i'm using a ATmega328P-PU, which has a slightly different pinout.

The differences between the ATtiny13 and the ATmega328 go deeper than the pinout. The ATmega328 is part of the megaAVR line; the ATtiny is part of the related but different tinyAVR line.

It may be possible to adapt the program for the ATtiny to an ATmega, but it will require significant changes, if it is possible at all. If you are not familiar enough with AVR development to make the appropriate changes on your own, get the correct controller.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.