Bluetooth ATtiny85

hi ,

I would like to know if the program below is correct, and mainly the use of SoftwareSeial and the pins used for RX AND TX i.e. which is the pin Rx is this pin 0 = connection pin 5 of the ATtiny85 ??? and pin TX is this pin 1= connection pin 6 of the ATtiny85

This is a small project that makes 2 motorbikes drive with an android app
My android app is communicating with the bluetooth as the flickering led turns off and a slow flicker occurs but nothing happens when i press the buttons of the app for forward left right

//C by Nikodem Bartnik http://nikodembartnik.pl/ email: nikodem.bartnik@gmail.com 04.2016r.

#include <SoftwareSerial.h>
SoftwareSerial bluetooth(0, 1);
bool on = 0;
int dir = 0;

void setup() {
bluetooth.begin(9600);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
bluetooth.setTimeout(100);
}
void loop() {
  if(bluetooth.available()){
 String data = bluetooth.readString();
       if(data.equals("W")){
  on = 1;
 }else if(data.equals("w")){
  on = 0;
 }     if(data.equals("F")){
  dir = 2;
 }else if(data.equals("R")){
  dir = 3;
 }else if(data.equals("L")){
  dir = 1;
 }else if(data.equals("S")){
  dir = 0;
 }
  //dir = data.substring(1, 2).toInt();
  bluetooth.println(data);
  bluetooth.print("on: ");
  bluetooth.println(on);
  bluetooth.print("dir: ");
  bluetooth.println(dir);
  }
  if(on){
    digitalWrite(2, HIGH);
  }else{
    digitalWrite(2, LOW);
  }
  /* 
dir = 0 - stop
dir = 1 - left
dir = 2 - forward
dir = 3 - right
*/
      if(dir == 0){
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
}else if(dir == 1){
    digitalWrite(3, HIGH);
    digitalWrite(4, LOW);
}else if(dir == 2){
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);
}else if(dir == 3){
    digitalWrite(3, LOW);
    digitalWrite(4, HIGH);
  }
  delay(10);
}

Use serial monitor and a Serial.print after bluetooth.avalable to tell that something is available.
Use a a Serial.print of the string after receving the data.

hi ,

Thank you for answering my question , but I don't think ATtiny85 works with the monitor of Arduino Uno , with the Arduino Uno I program the attiny85
I could be wrong because I don't really know how to make you proposal
I found a sketch of an ATtiny85 on the internet and want to know if this is correct on my project ( pin 5 = Tx ) (pin 6 = Rx)

Serial monitor reads ASCII coming via USB. There's no link to the controller producing the ASCII.

The diagram may be correct for your Attiny, it all depends on which ‘core’ you’re using and how that core defines the pins. I use Dr. Azzy’s TinyCore, and his github has the diagrams of the pinouts as they are set up in his core.

Edit: (Your diagram looks to come from his core, so if you’re using his core, that’s the right image.)

Ok I understand I think but my project is not connected to or with the Arduino uno
I first program the attiny85 and then I place the attiny in the project with the bluetooth

Ok I found the file so a first look is that Rx of the attiny85 is on pin 6 and TX on pin 5 I'm going to read it in the hope I understand everything , thank you for the answer to my question

If you are using the ATTinyCore core you do not need to use software serial if you are using the default Serial pins. Use Serial instead and connect BT RX to tiny85 pin 1 (physical pin 6) and BT TX to tiny85 pin 0 (physical pin 5). You can use SoftwareSerial if you need to use pins other than the defaults.

Here is test code to show the above:

//Sends from tiny85 to the Bluetooth device app
//Receives from Bluetooth device app to control state of LED on pin 3 (physical pin 2)

// BT TX to tiny85 pin 1 physical pin 6, BT RX to pin 0 physical pin 5

const byte ledPin = 3;

void setup()
{
   Serial.begin(9600);
   Serial.println("Bluetooth test program");
   pinMode(ledPin, OUTPUT);
}

void loop()
{
   // send periodic test phrase
   static unsigned long timer = 0;
   unsigned long interval = 2000;
   if (millis() - timer >= interval)
   {
      timer = millis();
      Serial.println("sending");
   }

   // receive 1 or 0 from app on Bluetooth device to control LED
   if(Serial.available())
   {
      char input = Serial.read();
      if(input == '1')
      {
         digitalWrite(ledPin, HIGH);         
      }
      else if(input == '0')
      {
         digitalWrite(ledPin, LOW);
      }
   }
}
1 Like

Do you have a little USB - Serial adapter? Like an FTDI breakout or something similar? Then you don't need to go through the UNO and can just connect RX-TX, TX-RX and GND-GND. Then you use the serial monitor on that little serial breakout to see what your program write to serial. It might be simpler than using the UNO as a serial port.

Forget about UNOs. They have nothing to do with this, with serial monitor. S M works like a terminal to which You send ASCII for displaying them provided You use a USB port on the PC.

Thanks Railroader and mixographer for the info and help, but I don't have a serial adapter or anything like that, the program doesn't help either, I don't get something from serial, I'll keep looking to see if I can find a better program, anyway thanks but I am an old (67y) trying arduino programmer and sometimes it works but not always
I think I already found something Rambo bluetooth micro robot

What does Your setup look like? Likely some Pc and the controller.
Can You make a block drawing showing what You've got?
Your long first sentence is hard to understand... We are newbies to You rigging...

ok what do i have :
1: schematic
2: homemade pcb for the BugBot
3; Homemade pcb for programming ATtiny85 on an arduino Uno
3: program see top of this page
I first load the arduinoISP program in the arduino Uno
Then I place the pcb for programming the attiny85 on the arduino uno and load the Bugbot program into the attiny85
Then I take out the attiny85 chip and put it in the pcb for the BugBot
Start the BugBot on the bt flashes quickly and then I also start the apk file of the app and the bt flashes slowly now I press the buttons of the app but nothing happens
That's what I have and do but it doesn't work

Thanks a lot! Great documentation.
Spending an entire life with electronics and programming, doing hands on work a lot I now days, being 69, wouldn't be comfortable with such a complicated circuit programming procedure.
Having a good way to debug is essential. I'm not familiar with the circuitry You use so it's hard to suggest what would be a simple way.

You use software Serial for reading the Bluetooth. It ought to be possible to use Software Serial for outputting debug info. But..... it must be possible to display it somewhere...

I'm pretty sure I see a mistake. The driver for the motors. It can't work.
Use the transistor to switch the low side of the motor! What is powering the motors, where does motor + come from?
Give us a link to the motor datasheet, or tell us about voltage and current.

I wanted to build this project for the grandchildren with their cell phone
(they can no longer live without a mobile phone)

I don't know anything about voltages or currents of the motors, I use old mini servos of which I scrapped the electronics and only keep the motor and gears in the housing so that I can mount it easily
The transistor I use is the BC337 which can withstand more current than the BC547
I also know that normally the motor is in the collector, but in the past I also put motors in the emitter that worked but I don't know more about it

I will make a other PCB with the motors in de collector site

That drawing could work but now You want to control the motors with the microcontroller.
I try to attach my suggestion here.

What do You think?

I think the flyback diode is missing.

I will make it maybe this will works i will take a 1N4148 for protect the attiny

Totally correct remark.