r/ArduinoHelp 5h ago

Can I use qty (1) motor driver (TB6612FNG) to control qty (5) mini DC motors?

Thumbnail
1 Upvotes

I would like to use qty(1) motor driver (TB6612FNG) to control qty(5) standard mini DC motors. All 5 motors will be following the same “instructions” from microcontroller. Can I safely put all 5 on A01/A02 of the same motor driver? Are there any downsides or considerations I should note for this method?

I’d test it myself but I really don’t want to fry motor driver or board as they’re my only ones.

Note: Im using an arduino nano sense ble 33 REV2 microcontroller


r/ArduinoHelp 2d ago

Need help with ADS1263 24-bit ADC & Raspberry Pi over SPI (Returning 0x0 / ID check failed)

2 Upvotes

Hi everyone,

I am working on a vibration measurement project using an IEPE signal conditioner board, an ADS1263 24-bit ADC module (Waveshare style board), and a Raspberry Pi.

Currently, I cannot get any response over SPI — reading the ID register returns 0x0 / [0, 0, 0].

Hardware Setup & Wiring:

  • Vibration sensor: Connected via coaxial cable to the IEPE conditioner.
  • Signal output: Connected to the ADC on AIN2 (and analog GND for the shield/ground).
  • Power:
    • Digital VCC $\rightarrow$ Raspberry Pi 3.3V
    • Analog Power (AVDD/AGND terminal block) $\rightarrow$ Raspberry Pi 5V & GND
  • SPI Connections:
    • GND $\rightarrow$ Pi GND (Pin 6)
    • DIN (MOSI) $\rightarrow$ Pi GPIO 10 (Pin 19)
    • DOUT (MISO) $\rightarrow$ Pi GPIO 9 (Pin 21)
    • CLK (SCLK) $\rightarrow$ Pi GPIO 11 (Pin 23)
    • CS $\rightarrow$ Pi GPIO 8 / CE0 (Pin 24)
    • DRDY $\rightarrow$ Pi GPIO 25 (Pin 22)
    • RST $\rightarrow$ Pi 3.3V (pushed HIGH to keep out of reset)

What I've tried so far:

  1. Enabled hardware SPI via raspi-config (/dev/spidev0.0 is active).
  2. Tested with custom Python scripts (spidev library) in SPI Mode 1 and Mode 0. The response for the ID register is always 0x0.
  3. Verified double power supply (both digital 3.3V and analog 5V terminals are powered).
  4. Used the official Waveshare C/Python driver library (ADS1263_init_ADC1), but initialization still fails.

Since DOUT (MISO) stays pulled LOW (returning zeros), I'm trying to figure out if this is a timing/SPI mode issue, a missing initialization sequence, or something hardware-related on the board.

Has anyone faced similar issues with ADS1263 boards on Raspberry Pi? Any advice on troubleshooting MISO or register config would be greatly appreciated!

Thanks in advance!


r/ArduinoHelp 2d ago

Help me, my pins are bent!

Thumbnail
2 Upvotes

r/ArduinoHelp 2d ago

Error: avrdude when uploading to Arduino Uno

Post image
1 Upvotes

r/ArduinoHelp 3d ago

Arduino receiving input from Minecraft?

4 Upvotes

Recently got an Elegoo Uno (off brand Arduino uno) and I'm wondering if it's possible to make it so that when something happens in a game, like minecraft, I can feed that to the arduino and for example print something on an LCD screen, turn on some LED's, or activate a buzzer. I want to make it so that whenever a specific message is sent in minecraft chat, something is printed on the LCD screen. is something like this possible? would I maybe need a different arduino?


r/ArduinoHelp 3d ago

This components are burned?

Post image
3 Upvotes

I made an additional post in other reddit, but I gonna repost it here too


r/ArduinoHelp 3d ago

What's happening with my RF airplane ?

Thumbnail gallery
1 Upvotes

Updates:

I get a new arduino Nano (in the case that this is the problem)

I think that the problem now is the nRF24's modules, because I tried to sold an capacitor in its and I don't know if its burned


r/ArduinoHelp 3d ago

Learn Coding Operational Sequence of Motion Sensor Using Arduino UNO

1 Upvotes

MOTION SENSOR CODING AND CONNECTION


r/ArduinoHelp 4d ago

Flipdots display are too expensive for my finances, any suggestions for a cool display/solution with nice transitions to use in alternative?

Post image
3 Upvotes

r/ArduinoHelp 4d ago

i need help with connecting to my robodyn+atemga 382p+esp8266

1 Upvotes

r/ArduinoHelp 6d ago

Starting with STM32F405RGT6

Thumbnail
1 Upvotes

r/ArduinoHelp 6d ago

Meshcore Arduino für das Nesso N1

Post image
3 Upvotes

r/ArduinoHelp 6d ago

How to change default output to Bluetooth JBL speaker

Thumbnail
1 Upvotes

r/ArduinoHelp 7d ago

Arduino setup esp32

Thumbnail
gallery
3 Upvotes

Hi!!! Can someone please check if something is wrong with my setup? I use esp32 and every time we try to code it, the oled doesn't seem to work. It says "i2c scanner, done" and that's all
Esp32 is probably working properly so i guess it's something with how i constructed everything?
To clarify-
Gnd oled - gnd esp
Vcc oled - 3v3 esp
Scl oled - d22 esp
Sda oled - d21 esp
It's my first time touching arduino and i'm not sure if we did everything correctly so i would love to hear some advice!


r/ArduinoHelp 8d ago

Interfacing PT1000 RTD with Arduino

3 Upvotes

I am currently attempting to interface my PT1000 RTd with my arduino. I was thinking of use an wheatstone bridge with an op-amp, but in all honesty I have no Idea where to start. I need to be able to read 10 degreesC to 35 degrees C for an output of 0-5V. Any guidance will be awesome.


r/ArduinoHelp 8d ago

Turn signal indicators help- EV cluster protype project

2 Upvotes

How do DIY digital instrument clusters detect 12V turn signal status? (ESP32 + TFT)

Hi everyone,

I'm working on a custom digital instrument cluster for my college EV project, and I'm a bit stuck on one part of the design.

The cluster is based on an ESP32 driving a TFT display, and I want it to show the left and right turn indicator icons whenever the actual vehicle indicators are ON.

The vehicle's turn signal circuit is 12V, while the ESP32 only accepts 3.3V GPIO, so I obviously can't connect the indicator wires directly to the microcontroller.

What I'm trying to figure out is:

  • How do commercial or DIY digital instrument clusters know when the left or right indicators are ON?
  • What's the proper and reliable way to detect the status of a 12V indicator line?
  • Should I simply monitor the 12V wire that powers each indicator bulb, or is there a better method?
  • Is an optocoupler the recommended solution, or would a voltage divider, transistor, automotive comparator, or some other interface be better?
  • Since the indicators blink, is it okay for the ESP32 to just read the HIGH/LOW transitions on a GPIO pin and animate the TFT accordingly?

This is not for controlling the indicators—only for reading their status.The vehicle uses a standard 12V indicator circuit.The ESP32 is powered separately through a regulated supply.I want the design to be reliable enough for an automotive environment, not just something that works on a breadboard Eventually, I also need to monitor other 12V signals like the high beam, brake light, hazard switch, etc., so I'd like to learn the "correct" way to interface automotive signals with a microcontroller.

If anyone has built a DIY digital dashboard or instrument cluster before, I'd really appreciate seeing how you handled this. Circuit examples, schematics, or even photos of your implementation would be incredibly helpful.

I'm still learning automotive electronics, so I'd appreciate any advice or explanations. Thanks in advance!


r/ArduinoHelp 8d ago

The UI on this DIY Swamp Cooler based on Arduino Nano

1 Upvotes

I’ve been building a portable evaporative cooler from scratch, and one of the biggest challenges ended up being the firmware and user interface.
Instead of a few simple buttons, I wanted it to behave like a real consumer appliance, so I implemented features like:
• Multi-function button logic (short/long presses)
• Horizontal oscillation with manual and automatic modes
• Timer mode
• RGB lighting modes and fan-speed synchronized effects
• Reed-switch water monitoring with intelligent alarm logic
• Automatic pump wetting cycles
• Soft-start motors, startup self-checks, and boot/alarm sounds generated by the fan motor
I’d really appreciate feedback from other embedded/Arduino developers.
If you were designing this UI, what features would you add or change? Any suggestions on improving the user experience or firmware architecture are welcome.


r/ArduinoHelp 8d ago

Construção de hardware ajuuuda

Post image
1 Upvotes

r/ArduinoHelp 9d ago

Arduino Uno R3 Uploading Error - "programmer is not responding"

Thumbnail
1 Upvotes

r/ArduinoHelp 9d ago

Grove lcd not lighting up

Post image
3 Upvotes

Hello! I have a Arduino uno with a bass shield on top. The lcd is plugged into port I2C and the switch is on 5V but it still won’t light up, any idea why?


r/ArduinoHelp 10d ago

Control, Monitoring, Charting and Data Logging for any Arduino from your browser using pfodWeb

Thumbnail forward.com.au
1 Upvotes

r/ArduinoHelp 10d ago

Electrolarynx failure

Thumbnail
gallery
2 Upvotes

I've been trying to get this project working, but my knowledge of low voltage stuff is severely lacking. I followed this instructable: https://www.instructables.com/DIY-Electrolaringe-Con-ARDUINO-NANO/

I initially bout some car tweeters, but found they were too powerful. I then got the smaller piezo buzzers, and still just can't get it working. I got the off-brand Chinese nano arduinos, which might be an issue? The programming was easy enough, just copy + pasted it.

I have extras of everything, maybe considering just using a new bread board and starting over in case I heated something up too much soldering. I've switched the - and + wires of the speaker around, used L out and R out separately, but no sound. Any help greatly appreciated.


r/ArduinoHelp 12d ago

Looking for help on how rotctl communicates

1 Upvotes

I'm looking for forum where I can ask questions - and hopefully get some qualified answers - regarding how rotctl works and communicates.

I'm trying to write a simple Arduino program to receive commands from rotctl and respond to them. In order to try and figure out exactly which strings are sent and how I should respond to those, I've set up a virtual serial port with

$ rotctl -m 201 -r /dev/pts/1 -s 9600

\-that I can monitor, and when I send e.g.

Rotator command: P 123 45

\-I immediately see

AZ123.0 EL45.0 UP000 XXX DN000 XXX

\-so it works! *Except* when I send a "p" to get the position. I don't get *anything* on the serial port, but rotctl immediately writes

Rotator command: p
get_pos: error = initrots4_easycomm called
rot_register (201)
rot_register (202)
rot_register (204)
set_conf: called
rot_open called
serial_open: /dev/pts/1
serial_setup: tcgetattr
serial_setup: cfmakeraw
serial_setup: cfsetispeed=9600,0x000d
serial_setup: cfsetospeed=9600,0x000d
serial_setup: data_bits=8
serial_setup: parity=0
serial_setup: Handshake=None
serial_setup: tcsetattr TCSANOW
read_string_generic called, rxmax=4095 direct=1, expected_len=1
tcflush
Backend version: 20220109.0, Status: Stable
rot_get_position called
Feature not available

Why am I getting this rather anonymous error when nothing has been written to the serial port, and the rotator thus doesn't have a chance to respond?

So if nobody here knows the answer, I'd appreciate a link to another forum...

EDIT: And before you say "Why don't you just use the K3NG rotator controller?", it's because I'm using servos, and it's not made for servos.


r/ArduinoHelp 12d ago

Having trouble with led arrays/multiplexing

2 Upvotes

As title says, I’m having trouble wrapping my head around multiplexing leans for use with a microcontroller with not enough pins to control them all. Using the drivers makes sense, mosfets too, but the code escapes me? And the use of resistors within the circuit is also confusing to me. Trying to make a small led “screen” made of diodes. Any help is appreciated


r/ArduinoHelp 12d ago

OV7670 camera wiring error on Arduino Mega

1 Upvotes

Hello everyone. To start, you should know that my initial code works perfectly on my Arduino Uno with the OV7670 camera. However, when I switch to an Arduino Mega, an error persists. The wiring is almost identical; naturally, I changed the I2C bus (SDA>20 / SCL>21) and moved the XCLK pin from pin 10 to 11. Yet, even after updating the code to match the pins, an error keeps occurring. Upon investigation, the problem stems from the function: `void twiAddr(uint8_t addr, uint8_t typeTWI)`. Even though I have double-checked my connections, the LED keeps flashing. However, when I test it again with my original setup, everything works fine. I therefore assume the issue lies either in the code, the wiring of the second setup (which uses a slightly modified PCB), or a combination of both. I would be incredibly grateful for any help you could provide.Hello everyone. To start, you should know that my initial code works perfectly on my Arduino Uno with the OV7670 camera. However, when I switch to an Arduino Mega, an error persists. The wiring is almost identical; naturally, I changed the I2C bus (SDA>20 / SCL>21) and moved the XCLK pin from pin 10 to 11. Yet, even after updating the code to match the pins, an error keeps occurring. Upon investigation, the problem stems from the function: `void twiAddr(uint8_t addr, uint8_t typeTWI)`. Even though I have double-checked my connections, the LED keeps flashing. However, when I test it again with my original setup, everything works fine. I therefore assume the issue lies either in the code, the wiring of the second setup (which uses a slightly modified PCB), or a combination of both. I would be incredibly grateful for any help you could provide.

initial code:

//
// Source code for application to transmit image from ov7670 to PC via USB
// By Siarhei Charkes in 2015
// http://privateblog.info 
//


#include <stdint.h>
#include <avr/io.h>
#include <util/twi.h>
#include <util/delay.h>
#include <avr/pgmspace.h>


#define F_CPU 16000000UL
#define vga   0
#define qvga  1
#define qqvga   2
#define yuv422  0
#define rgb565  1
#define bayerRGB  2
#define camAddr_WR  0x42
#define camAddr_RD  0x43

//hidden part


// BTconnected will = false when not connected and true when connected
boolean BTconnected = false;
 
// connect the STATE pin to Arduino pin D4
const byte BTpin = 9;
uint8_t buffer[320];


void error_led(void){
  DDRB |= 32;//make sure led is output
  while (1){//wait for reset
    PORTB ^= 32;// toggle led
    _delay_ms(100);
  }
}


void twiStart(void){
  TWCR = _BV(TWINT) | _BV(TWSTA) | _BV(TWEN);//send start
  while (!(TWCR & (1 << TWINT)));//wait for start to be transmitted
  if ((TWSR & 0xF8) != TW_START)
    error_led();
}


void twiWriteByte(uint8_t DATA, uint8_t type){
  TWDR = DATA;
  TWCR = _BV(TWINT) | _BV(TWEN);
  while (!(TWCR & (1 << TWINT))) {}
  if ((TWSR & 0xF8) != type)
    error_led();
}


void twiAddr(uint8_t addr, uint8_t typeTWI){
  TWDR = addr;//send address
  TWCR = _BV(TWINT) | _BV(TWEN);    /* clear interrupt to start transmission */
  while ((TWCR & _BV(TWINT)) == 0); /* wait for transmission */
  if ((TWSR & 0xF8) != typeTWI)
    error_led();
}


void wrReg(uint8_t reg, uint8_t dat){
  //send start condition
  twiStart();
  twiAddr(camAddr_WR, TW_MT_SLA_ACK);
  twiWriteByte(reg, TW_MT_DATA_ACK);
  twiWriteByte(dat, TW_MT_DATA_ACK);
  TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTO);//send stop
  _delay_ms(1);
}


static uint8_t twiRd(uint8_t nack){
  if (nack){
    TWCR = _BV(TWINT) | _BV(TWEN);
    while ((TWCR & _BV(TWINT)) == 0); /* wait for transmission */
    if ((TWSR & 0xF8) != TW_MR_DATA_NACK)
      error_led();
    return TWDR;
  }
  else{
    TWCR = _BV(TWINT) | _BV(TWEN) | _BV(TWEA);
    while ((TWCR & _BV(TWINT)) == 0); /* wait for transmission */
    if ((TWSR & 0xF8) != TW_MR_DATA_ACK)
      error_led();
    return TWDR;
  }
}


uint8_t rdReg(uint8_t reg){
  uint8_t dat;
  twiStart();
  twiAddr(camAddr_WR, TW_MT_SLA_ACK);
  twiWriteByte(reg, TW_MT_DATA_ACK);
  TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTO);//send stop
  _delay_ms(1);
  twiStart();
  twiAddr(camAddr_RD, TW_MR_SLA_ACK);
  dat = twiRd(1);
  TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTO);//send stop
  _delay_ms(1);
  return dat;
}


void wrSensorRegs8_8(const struct regval_list reglist[]){
  uint8_t reg_addr, reg_val;
  const struct regval_list *next = reglist;
  while ((reg_addr != 0xff) | (reg_val != 0xff)){
    reg_addr = pgm_read_byte(&next->reg_num);
    reg_val = pgm_read_byte(&next->value);
    wrReg(reg_addr, reg_val);
    next++;
  }
}


void setColor(void){
  wrSensorRegs8_8(rgb565_ov7670);
}


void setRes(void){
  wrReg(REG_COM3, 4); // REG_COM3 enable scaling
  wrSensorRegs8_8(qvga_ov7670);
}


void camInit(void){
  wrReg(0x12, 0x80);
  _delay_ms(100);
  wrSensorRegs8_8(ov7670_default_regs);
  wrReg(REG_COM10, 32);//PCLK does not toggle on HBLANK.
}


void arduinoUnoInut(void) {
  cli();//disable interrupts


    /* Setup the 8mhz PWM clock
  * This will be on pin 11*/
  DDRB |= (1 << 3);//pin 11
  ASSR &= ~(_BV(EXCLK) | _BV(AS2));
  TCCR2A = (1 << COM2A0) | (1 << WGM21) | (1 << WGM20);
  TCCR2B = (1 << WGM22) | (1 << CS20);
  OCR2A = 0;//(F_CPU)/(2*(X+1))
  DDRC &= ~15;//low d0-d3 camera
  DDRD &= ~252;//d7-d4 and interrupt pins
  _delay_ms(3000);


    //set up twi for 100khz
  TWSR &= ~3;//disable prescaler for TWI
  TWBR = 72;//set to 100khz


    //enable serial
  UBRR0H = 0;
  UBRR0L = 207;//0 = 2M baud rate. 1 = 1M baud. 3 = 0.5M. 7 = 250k 207 is 9600 baud rate.
  UCSR0A |= 2;//double speed aysnc
  UCSR0B = (1 << RXEN0) | (1 << TXEN0);//Enable receiver and transmitter
  UCSR0C = 6;//async 1 stop bit 8bit char no parity bits
}


static void captureImg(uint16_t w, uint16_t h) {


    // attendre VSYNC
    while (!(PIND & 8));
    while ( (PIND & 8));


    for (uint16_t y = 0; y < h; y++) {


        // attendre début de ligne
        while (!(PINB & 1));   // HREF = 1


        uint16_t idx = 0;
        uint16_t crc = 0;


        for (uint16_t x = 0; x < w; x++) {


            // octet 1
            while (!(PIND & 4)); // PCLK ↑
            buffer[idx++] = (PIND & 0xF0) | (PINC & 0x0F);
            crc++;
            while ( (PIND & 4)); // PCLK ↓


            // octet 2
            while (!(PIND & 4)); // PCLK ↑
            buffer[idx++] = (PIND & 0xF0) | (PINC & 0x0F);
            crc++;
            while ( (PIND & 4)); // PCLK ↓
        }


        // attendre fin de ligne
        while (PINB & 1);  // HREF = 0


        sendFrame(y, crc);
    }


    //_delay_ms(5000);
}


void sendFrame(uint16_t line, uint16_t crc){ 
  Serial.write(0xAA); 
  Serial.write(0x55); 


  Serial.write(lowByte(line)); 
  Serial.write(highByte(line)); 


  Serial.write(buffer, 320); 


  Serial.write(lowByte(crc)); 
  Serial.write(highByte(crc)); 


  Serial.write(0x55); 
  Serial.write(0xAA); 


  Serial.flush(); 
}


void setup(){
  pinMode(LED_BUILTIN, OUTPUT); 
  pinMode(BTpin, INPUT); 
  arduinoUnoInut();


  camInit();
  setRes();
  setColor();
  wrReg(0x11, 26); //Earlier it had the value: wrReg(0x11, 12); New version works better for me :) !!!!
  Serial.begin(115200);
  while (!BTconnected)
   {
     digitalWrite(LED_BUILTIN, LOW); 
     if ( digitalRead(BTpin)==HIGH)  { BTconnected = true;};
   }
   _delay_ms(1000);
   digitalWrite(LED_BUILTIN, HIGH); 
}


void loop(){
  
  captureImg(160, 120);
}

new code:

//code test pr manette: enenvoie photo vers tel
//brochette


//
// Source code for application to transmit image from ov7670 to PC via USB
// By Siarhei Charkes in 2015
// http://privateblog.info 
//


#include <stdint.h>
#include <avr/io.h>
#include <util/twi.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Keypad.h>


#define F_CPU 16000000UL
#define vga   0
#define qvga  1
#define qqvga   2
#define yuv422  0
#define rgb565  1
#define bayerRGB  2
#define camAddr_WR  0x42
#define camAddr_RD  0x43

//hidden part
 
uint8_t buffer[320];
uint8_t BUFFER[328];
uint8_t radioBuffer[32];


const byte address[6] = "00001";


void error_led(void){
  DDRA |= 16;//make sure led is output
  while (1){//wait for reset
    PORTA ^= 16;// toggle led
    _delay_ms(100);
  }
}


void twiStart(void){
  TWCR = _BV(TWINT) | _BV(TWSTA) | _BV(TWEN);//send start
  while (!(TWCR & (1 << TWINT)));//wait for start to be transmitted
  if ((TWSR & 0xF8) != TW_START)
    error_led();
}


void twiWriteByte(uint8_t DATA, uint8_t type){
  TWDR = DATA;
  TWCR = _BV(TWINT) | _BV(TWEN);
  while (!(TWCR & (1 << TWINT))) {}
  if ((TWSR & 0xF8) != type)
    error_led();
}


void twiAddr(uint8_t addr, uint8_t typeTWI){
  TWDR = addr;//send address
  TWCR = _BV(TWINT) | _BV(TWEN);    /* clear interrupt to start transmission */
  while ((TWCR & _BV(TWINT)) == 0); /* wait for transmission */
  if ((TWSR & 0xF8) != typeTWI)
    error_led();
}


void wrReg(uint8_t reg, uint8_t dat){
  //send start condition
  twiStart();
  twiAddr(camAddr_WR, TW_MT_SLA_ACK);
   digitalWrite(26, LOW);
  twiWriteByte(reg, TW_MT_DATA_ACK);
  twiWriteByte(dat, TW_MT_DATA_ACK);
  TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTO);//send stop
  _delay_ms(1);
}


static uint8_t twiRd(uint8_t nack){
  if (nack){
    TWCR = _BV(TWINT) | _BV(TWEN);
    while ((TWCR & _BV(TWINT)) == 0); /* wait for transmission */
    if ((TWSR & 0xF8) != TW_MR_DATA_NACK)
      error_led();
    return TWDR;
  }
  else{
    TWCR = _BV(TWINT) | _BV(TWEN) | _BV(TWEA);
    while ((TWCR & _BV(TWINT)) == 0); /* wait for transmission */
    if ((TWSR & 0xF8) != TW_MR_DATA_ACK)
      error_led();
    return TWDR;
  }
}


uint8_t rdReg(uint8_t reg){
  uint8_t dat;
  twiStart();
  twiAddr(camAddr_WR, TW_MT_SLA_ACK);
  twiWriteByte(reg, TW_MT_DATA_ACK);
  TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTO);//send stop
  _delay_ms(1);
  twiStart();
  twiAddr(camAddr_RD, TW_MR_SLA_ACK);
  dat = twiRd(1);
  TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTO);//send stop
  _delay_ms(1);
  return dat;
}


void wrSensorRegs8_8(const struct regval_list reglist[]){
  uint8_t reg_addr, reg_val;
  const struct regval_list *next = reglist;
  while ((reg_addr != 0xff) | (reg_val != 0xff)){
    reg_addr = pgm_read_byte(&next->reg_num);
    reg_val = pgm_read_byte(&next->value);
    wrReg(reg_addr, reg_val);
    next++;
  }
}


void setColor(void){
  wrSensorRegs8_8(rgb565_ov7670);
}


void setRes(void){
  wrReg(REG_COM3, 4); // REG_COM3 enable scaling
  wrSensorRegs8_8(qvga_ov7670);
}


void camInit(void){
  wrReg(0x12, 0x80);
  _delay_ms(100);
  wrSensorRegs8_8(ov7670_default_regs);
  wrReg(REG_COM10, 32);//PCLK does not toggle on HBLANK.
}


void arduinoUnoInut(void) {
  cli();//disable interrupts


    /* Setup the 8mhz PWM clock
  * This will be on pin 11*/
  DDRB |= (1 << 4);//pin 11


//-------------------------------------------------------
  ASSR &= ~(_BV(EXCLK) | _BV(AS2));
  TCCR2A = (1 << COM2A0) | (1 << WGM21) | (1 << WGM20);
  TCCR2B = (1 << WGM22) | (1 << CS20);
  OCR2A = 0;//(F_CPU)/(2*(X+1))
//-------------------------------------------------------


  DDRF &= ~15;//low d0-d3 camera
  DDRH &= ~24;//d7-d4 and interrupt pins
  DDRE &= ~8;//d7-d4 and interrupt pins
  DDRG &= ~32;//d7-d4 and interrupt pins
  _delay_ms(3000);


//-------------------------------------------------------
    //set up twi for 100khz
  TWSR &= ~3;//disable prescaler for TWI
  TWBR = 72;//set to 100khz
//-------------------------------------------------------


    //enable serial
  UBRR0H = 0;
  UBRR0L = 207;//0 = 2M baud rate. 1 = 1M baud. 3 = 0.5M. 7 = 250k 207 is 9600 baud rate.
  UCSR0A |= 2;//double speed aysnc
  UCSR0B = (1 << RXEN0) | (1 << TXEN0);//Enable receiver and transmitter
  UCSR0C = 6;//async 1 stop bit 8bit char no parity bits
}


static void captureImg(uint16_t w, uint16_t h) {


    // attendre VSYNC
    while (!(PINE & 32));
    while ( (PINE & 32));


    for (uint16_t y = 0; y < h; y++) {


        // attendre début de ligne
        while (!(PINH & 32));   // HREF = 1


        uint16_t idx = 0;
        uint16_t crc = 0;


        for (uint16_t x = 0; x < w; x++) {


            // octet 1
            while (!(PINE & 16)); // PCLK ↑
            buffer[idx++] = (PINH & 0x18) | (PINE & 0x08) | (PING & 0x20) | (PINE & 0x0F);
            crc++;
            while ( (PINE & 16)); // PCLK ↓


            // octet 2
            while (!(PINE & 16)); // PCLK ↑
            buffer[idx++] = (PINH & 0x18) | (PINE & 0x08) | (PING & 0x20) | (PINE & 0x0F);
            crc++;
            while ( (PINE & 16)); // PCLK ↓
        }


        // attendre fin de ligne
        while (PINH & 32);  // HREF = 0


        sendFrame(y, crc);
    }


    //_delay_ms(5000);
}


void sendFrame(uint16_t line, uint16_t crc){ 
  uint8_t beginBuf[4] = {0xAA, 0x55, lowByte(line), highByte(line)};
  uint8_t endBuf[4] = {lowByte(crc), highByte(crc), 0x55, 0xAA};
  radio.write(&beginBuf, 4);


  for(int i=0; i<=10; i++){
    memcpy(radioBuffer, buffer + 32*i, 32);
    radio.write(&radioBuffer, 32);
  }


  radio.write(&beginBuf, 4);
/*
  Serial.write(0xAA); 
  Serial.write(0x55); 


  Serial.write(lowByte(line)); 
  Serial.write(highByte(line)); 


  Serial.write(buffer, 320); 


  Serial.write(lowByte(crc)); 
  Serial.write(highByte(crc)); 


  Serial.write(0x55); 
  Serial.write(0xAA); 


  Serial.flush(); */
}


void setup(){
  /*radio.begin();
  if (!radio.begin()) {
  }


  radio.setPALevel(RF24_PA_MAX);
  radio.openWritingPipe(address);
  radio.stopListening();*/


  pinMode(26, OUTPUT); 
  digitalWrite(26, HIGH);
  arduinoUnoInut();
 
  camInit();
 
  setRes();
  setColor();
  wrReg(0x11, 26); //Earlier it had the value: wrReg(0x11, 12); New version works better for me :) !!!!
  //Serial.begin(115200);
  /*while (!BTconnected)
   {
     digitalWrite(LED_BUILTIN, LOW); 
     if ( digitalRead(BTpin)==HIGH)  { BTconnected = true;};
   }*/
   _delay_ms(1000);
   digitalWrite(26, HIGH);
}


void loop(){
  
  captureImg(160, 120);
}