ATTINY4313 and HC05 problems

Hello i am trying to use attiny4313 and HC05 with uln2003 + 28byj-48, the problems I encoutered are that I cant get the attiny4313 to communicate through hc05 with bt terminal. It also doesnt read the value of the state pin of hc05, so idk what is the problem.

#include <SoftwareSerial.h>

// Vystupy pro ULN2003 (motorek)
#define IN1 PD2
#define IN2 PD3
#define IN3 PD4
#define IN4 PD5

#define ledV PB4 // LED pracuje
#define ledP PB3 // LED pro stav BT
#define staP PD6 // Vstup pro čtení stavu

SoftwareSerial BTSerial(PD0, PD1); // RX (2) | TX (3) pro HC-05

char command[16];  // Buffr pro příjem příkazu (zkráceno)
const int step_sequence[8][4] = {
    {1, 0, 0, 0},
    {1, 1, 0, 0},
    {0, 1, 0, 0},
    {0, 1, 1, 0},
    {0, 0, 1, 0},
    {0, 0, 1, 1},
    {0, 0, 0, 1},
    {1, 0, 0, 1}
};

void stepMotor(int step) {
    digitalWrite(IN1, step_sequence[step][0]);
    digitalWrite(IN2, step_sequence[step][1]);
    digitalWrite(IN3, step_sequence[step][2]);
    digitalWrite(IN4, step_sequence[step][3]);
}

void fullRotation() {
    const int steps_per_rev = 4096;
    for (int i = 0; i < steps_per_rev; i++) {
        stepMotor(i % 8);
        delayMicroseconds(1500);
    }
}

void halfRotation() {
    const int steps_per_half = 2048;
    for (int i = 0; i < steps_per_half; i++) {
        stepMotor(i % 8);
        delayMicroseconds(1500);
    }
}

void setup() {
    BTSerial.begin(9600); // HC-05 je standardně na 9600 baud
    pinMode(IN1, OUTPUT);
    pinMode(IN2, OUTPUT);
    pinMode(IN3, OUTPUT);
    pinMode(IN4, OUTPUT);
    pinMode(ledP, OUTPUT);
    pinMode(staP, INPUT);
    pinMode(ledV, OUTPUT);
}

void loop() {
    if (digitalRead(staP) == 1) {
      digitalWrite(ledP, HIGH);
    } else {
        digitalWrite(ledP, LOW);
    }

    if (BTSerial.available()) {
        BTSerial.readBytesUntil('\n', command, sizeof(command)); // Čtení příkazu z Bluetooth
        if (command[0] == 'c' && command[1] == 'k' && command[2] == 'j') {
            int delayTime = atoi(&command[4]); // Přečte číslo po prefixu "ckj_"
            BTSerial.println("čekám");
            digitalWrite(ledV, HIGH);
            if (delayTime > 0) {
                delay(delayTime);
                fullRotation();
                BTSerial.println("Hotovo, dočkal jsem");
                digitalWrite(ledV, LOW);
            }
        } else if (command[0] == 'b' && command[1] == 'u' && command[2] == 'l' && command[3] == 'b') {
            BTSerial.println("pootáčím");
            digitalWrite(ledV, HIGH);
            delay(2000);
            halfRotation();  // nebo halfRotation, podle potřeby
            BTSerial.println("pootočeno");
            digitalWrite(ledV, LOW);
    }
  }
}



This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.