I need help in Programming Attiny85 via Arduino for LED turn off and On

Hi, I am currently working on a school project and trying to communicate with a bluetooth application to a bluetooth connected to the ATtiny85 for dimming the led with a slider from the app also do turn on and off function. Do you any example code I can use or can you help me to make one. Thanks in advance and I await your response.

Hereis my code but I don't get any respond on pin 0 to turn and off the LED when connected with the bluetooth any help.

/*
This code will run the bluetooth as slave
pressing 1 turns on led 4
pressing 0 turns off led 4
*/
 
#include    //Software Serial Port
#define RxD 1
#define TxD 2
 
SoftwareSerial blueToothSerial(RxD,TxD);

int led = 0;
 
void setup() 
{ 
  pinMode(RxD, INPUT);
  pinMode(TxD, OUTPUT);
  blueToothSerial.begin(9600);
  pinMode(led,OUTPUT);
  digitalWrite(led,HIGH);
 
} 
 
void loop() 
{ 
  char recvChar;
  while(1){
    //check if there's any data sent from the remote bluetooth shield
    if(blueToothSerial.available()){
      recvChar = blueToothSerial.read();
      
        if(recvChar == '1')
          digitalWrite(led,HIGH);  
       
        else
          digitalWrite(led,LOW); 
    }
  }
} 
 
}

Regards,
Otega

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

@ekpamaku,
Welcome to the forum.

Your post has been split off into it's own thread, it didn't belong in the '1284P core files discussion.

Cross-posting in multiple areas of the forum is a BIG no-no.

http://forum.arduino.cc/index.php?topic=243698.0

Other threads removed. Replies go here.

@ Ray Burne Sorry.. @ Author thanks..

when you say pin0 what do you mean? you have pins 1 and 2 defined....pin0 of what?

be aware that digitalPin and physical pin arent the same thing, not sure how digitalPin maps to physical pin on the 85, it depends on the specific core in use and im not at my main pc at the mo so its difficult to lookup various options.

what I DO know is that pin 1 on an 85, I.e the one at the top left of the chip next to the index dot is RESET and if you are using ISP programming, you cannot use that pin as an IO pin, AND youd need to set a fuse to get around that...RSTDISBL or similar name (too lqzy to check, but see the datasheet and it will become immediately apparent)

so...how are you getting your sketch into the 85? do you have a schematic of the wiring to al the other pins? I know nohting of the bluetooth softserial etc especially on tinies, so I dont ev3n know if what you are trying to do is possible, but you have some more basic hurdles to overcome first in working out which physical pin maps to what arduino thinks is a digitalPin, and avoiding using the RESET line

the arduino ide is aimed at, tailored for, and good at Arduino hardware. Once you step off the beaten track and use a homebrew setup or "unusual" mcu, you are kind of on your own...you cannot countenance doing it without knowing a large portion of the datasheet for your chosen mcu or at the very least the relationship between the datasheet pinouts and your code...get reading!!

@ BareMetal , Thanks for the post. I mean by PIN 0 = Digital 5 as you can see from my attachment that how i did my wiring I tried the blink program and other programs it works fine but when I try to do serial communication via the Bluetooth as in to turn and off the LED and do dimming it doesn't respond it only turn of the LED but does not come on.

For my Serial port I define pin 1 and 2 as TX,RX in the 85 so i just gave my bluetooth 5 volts and connect TX to the RX pin AND RX to TX of the 85. I tried to inter change but still didn't not work.

I try the same program and bluetooth on the atmaga and works fine with the bluetooth but for the 85 not. any help to get the 85 working will be nice..

ATtiny45-85.png

@ BareMetal

download.jpg

I still dont get you. the 85 has no concept of rx and tx, it has no hw serial, you knew that, its why you use soft serial...designed for arduino digital pins, another concept the 85 has no knowledge of...its NOT an arduino..you HAVE to know the mapping between what you are calling pin1 and pin2 and rx and tx and the physical pins on the 85.

I see the arduino.as.isp wiring, which answers me re how you get the sketch into the 85, but where are your so called tx and rx wires when you run the sketch? do you disconnect the isp lines before testing your code? do you have a schematic showing the 85 and bluetooth while it is running? even a blurred photo would be bettervthan me just guessing

better still, since I know th 85 pinout and there are only 8, list me wht is connected to what when it is RUNNING

85pins
1 ?
2?
3?
4 GND
5?
6?
7?
8 5V

fill in the ? for me on your runtime setup (NOT during isp uploading), there are only six left...

also, what is that weird include meant to do?

I don't get while (1)

Shouldn't it be just

void loop() 
{ 
  char recvChar;  // Should this be in   void setup ()  ???
  if(blueToothSerial.available())
  {
    recvChar = blueToothSerial.read();
    if(recvChar == '1')
    {
      digitalWrite(led,HIGH);  
    }
    else   // meaning that   recvChar != '1'
    {
      digitalWrite(led,LOW); 
    }
  }

Is ATtiny85 with its internal clock OK with 9600 baud? (IOW, maybe try something slower?)
}

is right...the while is redundant since loop() already sits inside an infinite loop...which is kinda where it gets its name...but it doesnt actually hurt or break or change anything, its just inefficient/redundant/about 3 or 4 bytes fatter sketch.

i cant be bothered doing the 1mhz vs 9600 baud maths, but you may well have a point there, bearing in mind uno e.g. runs at 12mhz.
I still want to see the runtime wiring.

Pin 7 = connected to the tx pin of my bluetooth
Pin 6 = connected to the rx pin of my bluetooth
pin 3 = connected to the LED pin of my bluetooth.

the include is define the pin 7 and 6 ( which is 2&1 for the 85) as the serial ports.#
and I was using the While(1) to let it constantly stay in the loop. i also tried a smaller board rate(4800) same behavior

But what am trying to do is to generate a pwm signal to dim a LED and also turn on and off the LED, I have an application with a slider that send the signal from the app via the bluetooth from 0 - 255 to control the led from the 85. but it's not working for me.

Pin 7 = connected to the tx pin of my bluetooth

BT TX should go to softwareserial RX (and vice versa).

Physical pin 7 of ATtiny is "logical" pin 2. So pin 2 should be softwareserial receive, shouldn't it?

#define RxD 1
#define TxD 2
SoftwareSerial blueToothSerial(RxD,TxD);

ekpamaku:
Pin 7 = connected to the tx pin of my bluetooth
Pin 6 = connected to the rx pin of my bluetooth
pin 3 = connected to the LED pin of my bluetooth.

the include is define the pin 7 and 6 ( which is 2&1 for the 85) as the serial ports.#
and I was using the While(1) to let it constantly stay in the loop. i also tried a smaller board rate(4800) same behavior

But what am trying to do is to generate a pwm signal to dim a LED and also turn on and off the LED, I have an application with a slider that send the signal from the app via the bluetooth from 0 - 255 to control the led from the 85. but it's not working for me.

you arent listening. pins in the arduino ide arent the same as physical pins. if you use 7 in arduino pinmode is IS NOT PHYSICAL PIN 7 ON THE CHIP, except by accident, im too lazy to check. I need to know what you have connected to THE PHYSICAL PINS and you still havent told me. the pins on the chip dont have defines, they are made of metal. they are numbered from 1 to 8 anticlockwise form the dotted top left corner. again I say, pin 1 is RESET and cannot be used for io without setting fuses.

if yoh cant answer simple questions I cant help yoh tell me what is connected to each and every pin OF THE CHIP. the chip, not your code, forget the code. it doesnt work. dont tell me about code, dont tell me about defines. dont tell me about arduino logical "digital pins" they are an invention of the arduino IDE and have nothing, but nothing to do with what is connected TO YOUR CHIP.

I cant make it any clearer. tell me what is wired to each and every leg of your chip, from 1 to 8. 4 has to be gnd and 8 has to be vcc. if there is anything on 1, it aint going to work...so now what is on chip legs 2,3,5,6 and 7? phew.

you set led to 0. this is PB0 so its on physical pin 5, yet u say your led is on pin3. I presume you mean physical pin3 which is obviously wrong, since that is PB4. what makes u think led =0 maps to pin 3, physical OR logical?

you really need to understand the mapping between arduino IDE pins and physical pins before trying something like this. arduino IDE is designed for arduinos. You are not using an arduino, you are using a bare 85. why should arduino code map to it? what if arduino IDE pin 6 mapped to physical pin 19...on an arduino wibble9999....why should it map to pin 19 on a tiny85?

might it be because the 85 only has 8 pins? do you see the problem now? arduino IDE pin numbers have nothing to do with the physical pin (leg) numbers on a chip.

every mcu is different. the IDE cleverly hides the underlying hardware from the user....arduino then print the logical pin number next to the physical pin of whatever chip your chosen arduino board uses. logical pin 13 might be physical pin 22 on one chip and 6 on another type...how do you reckon the
iDE copes eith the Due, which has a totally different family of processor with about a million legs on it? it could ben physical pin 255. ok im exaggerating but I hope you are starting to see how dirty your hands need to get if you insist on using a chip the IDE was never designed for.