B-Robot on Arduino …
 
Share:
Notifications
Clear all

B-Robot on Arduino uno

Page 1 / 2

2b645ff219ed1979318b47beb53c9d13?s=80&d=mm&r=g
(@maxmagic1986)
Member
Joined: 6 years ago
Posts: 5
Topic starter  

I want to build B-robot using Atmega328 chip. How i need to change motor ports and what about timers configuration? I do not use wifi and ultrasonic sensors. Interesting only balancing algorhytm and motor controls. Can somebody help me?


Quote
dharmahomesuites
(@dharmahomesuites)
Member
Joined: 6 years ago
Posts: 1

ReplyQuote
275024ff50a20318a5b12fb3ace69c25?s=80&d=mm&r=g
(@anton-mark)
Member Customer
Joined: 6 years ago
Posts: 175
 

Hi Max,
The B-robot code uses the two TIMERS of the Arduino Leonardo at the same time, so you would need the same Atmega processor that the Arduino Leonardo mounts or modify the code


ReplyQuote
1a042a675fa2180f0ff4702fe297c4db?s=80&d=mm&r=g
(@sasa999)
Member
Joined: 6 years ago
Posts: 106
 

Timers is no problem. You can use only one timer if you want.


ReplyQuote
7ed366903443b5baead68657f65dcacb?s=80&d=mm&r=g
(@legin-37)
Member
Joined: 6 years ago
Posts: 14
 

Timers is no problem. You can use only one timer if you want.

Timer1 or Timer2?


ReplyQuote
1a042a675fa2180f0ff4702fe297c4db?s=80&d=mm&r=g
(@sasa999)
Member
Joined: 6 years ago
Posts: 106
 

Timer0 and timer2 are 8bit timer, where timer1 is a 16bit timer.
Why do you wany use Uno and change code? Why not ProMicro?


ReplyQuote
7ed366903443b5baead68657f65dcacb?s=80&d=mm&r=g
(@legin-37)
Member
Joined: 6 years ago
Posts: 14
 

Timer0 and timer2 are 8bit timer, where timer1 is a 16bit timer.
Why do you wany use Uno and change code? Why not ProMicro?

Because UNO is more cheaper and normally we have several in the desk.


ReplyQuote
1a042a675fa2180f0ff4702fe297c4db?s=80&d=mm&r=g
(@sasa999)
Member
Joined: 6 years ago
Posts: 106
 

Because UNO is more cheaper …

More cheaper!!!???
ProMicro is for 4$. That is less than cost petrol for driving to nearest store:)
http://www.ebay.com/itm/New-Pro-Micro-ATmega32U4-5V-16MHz-Replace-ATmega328-Arduino-Pro-Mini-/131513277878?hash=item1e9ecd5db6rUAAAOSwPgxVNhve

Any way, it is up to you, use Uno or other board.


ReplyQuote
2b645ff219ed1979318b47beb53c9d13?s=80&d=mm&r=g
(@maxmagic1986)
Member
Joined: 6 years ago
Posts: 5
Topic starter  

i am already made the cirquit and pcb using atmega328p. just have a lot of those chips in my house. So only the code part must be modified. Trying to adapt code by my own, but get stacked. My knowledge is not enough.


what ports i can use for stepper control in atmega 328 and what timer?


eX-robot uses only one timer1 in to control both motors and ultrasonic sensor. Timer1 is 16 bit timer. on atmega 328 timer1 also 16 bit. maybe i can use his code and just change ports and pins config?


ReplyQuote
7ed366903443b5baead68657f65dcacb?s=80&d=mm&r=g
(@legin-37)
Member
Joined: 6 years ago
Posts: 14
 

Because UNO is more cheaper …

More cheaper!!!???
ProMicro is for 4$. That is less than cost petrol for driving to nearest store:)
http://www.ebay.com/itm/New-Pro-Micro-ATmega32U4-5V-16MHz-Replace-ATmega328-Arduino-Pro-Mini-/131513277878?hash=item1e9ecd5db6rUAAAOSwPgxVNhve

Any way, it is up to you, use Uno or other board.

Sorry, I´did want to say “more cheaper than Leonardo”, but the cost its not the reason. Really the reason is that I have two UNO on the desk without use. D


ReplyQuote
c640118211c1a15d75d716f924eedf77?s=80&d=mm&r=g
 KomX
(@komx)
Member
Joined: 6 years ago
Posts: 95
 

i am already made the cirquit and pcb using atmega328p. just have a lot of those chips in my house. So only the code part must be modified. Trying to adapt code by my own, but get stacked. My knowledge is not enough.


what ports i can use for stepper control in atmega 328 and what timer?


eX-robot uses only one timer1 in to control both motors and ultrasonic sensor. Timer1 is 16 bit timer. on atmega 328 timer1 also 16 bit. maybe i can use his code and just change ports and pins config?

Good day, MaxMagic1986.
Please see the differences in the operation of the timer1 for ATmega328P and ATmega32u4.

Arduino UNO (pinout & function pin)
atmega328 qtfp

Arduino Leonardo & Pro Micro (pinout & function pin)
atmel atmega32u4 pinout diagram

I’ll try to help you this weekend.


ReplyQuote
c640118211c1a15d75d716f924eedf77?s=80&d=mm&r=g
 KomX
(@komx)
Member
Joined: 6 years ago
Posts: 95
 

So, set the timer1 registers serving in both chips are not the same.
The Atmega328 no OCR1C register.
Therefore, we can only cater for two events (sonar excluded).

The initialization procedure:

void eX_Motors_Init(void)
{ 
  dir_M1 = 0;
  dir_M2 = 0;
  TCCR1A = 0;
  TCCR1B = B00000010;
  TCCR1C = 0;
  OCR1A  = ZERO_SPEED;
  OCR1B  = ZERO_SPEED;
  TCNT1  = 0;
  TIMSK1 = B00000110;
  digitalWrite(MOTORS_ENABLE_PIN,HIGH);
}

and interrupts

ISR(TIMER1_COMPA_vect)
{
  if (dir_M1==0) return;
  if (dir_M1>0)
  {
    digitalWrite(MOTORS_DIR_PIN,HIGH);            // DIR Motors (Forward for Motor1)
  }
  else
  {
    digitalWrite(MOTORS_DIR_PIN,LOW);            // DIR Motors (Revers for Motor1)
  }
  OCR1A  = OCR1A + period_M1;
    __asm__ __volatile__ (
    "nop" "nt"
    "nop" "nt"
    "nop" "nt"
    "nop");
  digitalWrite(MOTOR1_STEP_PIN,HIGH);           // STEP MOTOR 1
  delay_1us();  
  digitalWrite(MOTOR1_STEP_PIN,LOW); 
}

ISR( TIMER1_COMPB_vect )
{
  if (dir_M2==0)    return;
  if (dir_M2>0)
  {
    digitalWrite(MOTORS_DIR_PIN,LOW);            // DIR Motors (Revers for Motor2)
  }
  else
  {
    digitalWrite(MOTORS_DIR_PIN,HIGH);            // DIR Motors (Forward for Motor2)
  }
  OCR1B  = OCR1B + period_M2;
      __asm__ __volatile__ (
    "nop" "nt"
    "nop" "nt"
    "nop" "nt"
    "nop");
  digitalWrite(MOTOR2_STEP_PIN,HIGH);           // STEP MOTOR 2
  delay_1us();  
  digitalWrite(MOTOR2_STEP_PIN,LOW); 
}

Since we control pins in software, you can select any of the available pins.


ReplyQuote
2b645ff219ed1979318b47beb53c9d13?s=80&d=mm&r=g
(@maxmagic1986)
Member
Joined: 6 years ago
Posts: 5
Topic starter  

the ex robot code does not compiling. I use ide version 1.06

and in the code of ex robot alot of unusial code that i dont need. Wifi, ultrasonic, led’s, servo and osc. I need that robot only balancing after switch on. Battery sensor also does not need. Where i need to put this part of code. can some body please send working example?


ReplyQuote
2b645ff219ed1979318b47beb53c9d13?s=80&d=mm&r=g
(@maxmagic1986)
Member
Joined: 6 years ago
Posts: 5
Topic starter  

i try to add this part of code to EX_robot file and remove ewerything that i not use. Not working. but compiling. i want to just made standing balancing robot without autonomus mode, led’s and servos.


i have connected these pins

motors enable -pin 4
motors dir – pin6
motor1 – step 13
motor2 step -7

have modified ex_pins file without port change.


ReplyQuote
2b645ff219ed1979318b47beb53c9d13?s=80&d=mm&r=g
(@maxmagic1986)
Member
Joined: 6 years ago
Posts: 5
Topic starter  

and what resolution of motors i should use? Maybe here is somebody who can help me with code? I’ve been spend many hours soldering pcb, an wiring everything. I not use 3d printed parts, everything done with hands from alluminium. It is sad thing, that robot does not want to work with atmega 328, and the code itself is dificult for understand for me.


motors only start spining little bit immedeatly after switching on. 1 sec, not more and then device not responding


ReplyQuote
Page 1 / 2
Share: