Store › Forums › Video Experimenter › Bugs/Problems › VE and L298P motor shield
- This topic has 9 replies, 2 voices, and was last updated 10 years, 6 months ago by fph.
-
AuthorPosts
-
April 24, 2014 at 6:16 pm #691fphMember
Hello,
We are trying to do a fish on wheels build as a school project. Like this: http://www.youtube.com/watch?v=YbNmL6hSNKw
We use this http://www.dfrobot.com/wiki/index.php/Cherokey_4WD_Mobile_Platform_%28SKU:ROB0102%29 as our platform, and an arduino UNO together with the Video Experimenter Shield.We get the VE shield to work just fine at tracking our fish/laser pointer.
We have stacked the VE shield on the UNO, and connected the pin outs from the Cherokey to pins 3,5,10 and 11 on the VE.
The Cherokey works when we only run code for the motors, but as soon as we tried to put together the code for the VE and the motors we ran into a problem. The VE is still working as intended. We get proper tracking, and also image on our monitor, but we only get one of the two motors on the cherokey to run.This is a stripped down version of the code we are using to troubleshoot:
//DEFINISJONER FOR VIDEO SHIELD
#include
#include
#define W 128
#define H 96
//INITIALISERINGER FOR VIDEO SHIELD
TVout tv;
unsigned char x,y;
unsigned char c;
unsigned char minX,minY,maxX,maxY;
char s[32];
//INITIALISERINGER FOR MOTORKONTROLL
int E1 = 5; //M1 Speed Control
int E2 = 10; //M2 Speed Control
int M1 = 3; //M1 Direction Control
int M2 = 11; //M2 Direction Control
void setup()
{
tv.begin(PAL, W, H);
initOverlay();
initInputProcessing();
tv.select_font(font4x6);
tv.fill(0);
}
void initOverlay() {
TCCR1A = 0;
// Enable timer1. ICES0 is set to 0 for falling edge detection on input capture pin.
TCCR1B = _BV(CS10);
// Enable input capture interrupt
TIMSK1 |= _BV(ICIE1);
// Enable external interrupt INT0 on pin 2 with falling edge.
EIMSK = _BV(INT0);
EICRA = _BV(ISC11);
}
void initInputProcessing() {
// Analog Comparator setup
ADCSRA &= ~_BV(ADEN); // disable ADC
ADCSRB |= _BV(ACME); // enable ADC multiplexer
ADMUX &= ~_BV(MUX0); // select A2 for use as AIN1 (negative voltage of comparator)
ADMUX |= _BV(MUX1);
ADMUX &= ~_BV(MUX2);
ACSR &= ~_BV(ACIE); // disable analog comparator interrupts
ACSR &= ~_BV(ACIC); // disable analog comparator input capture
}
// Required
ISR(INT0_vect) {
display.scanLine = 0;
}
//MOTOR CONTROL FUNCTIONS
//FORWARD
void advance(char a,char b)
{
analogWrite (E1,a); //PWM Speed Control
digitalWrite(M1,HIGH);
analogWrite (E2,b);
digitalWrite(M2,HIGH);
}
void loop(void)
{
advance (100,100);
tv.capture();
// uncomment if tracking dark objects
//tv.fill(INVERT);
//LOGIKK FOR Å BEREGNE "BOUNDING BOX" RUNDT OBJEKT
minX = W;
minY = H;
maxX = 0;
maxY = 0;
boolean found = 0;
for(int y=5;y<80;y++) {
for(int x=10;x<110;x++) {
c = tv.get_pixel(x,y);
if (c == 1) {
found = true;
if (x < minX) {
minX = x;
}
if (x > maxX) {
maxX = x;
}
if (y < minY) {
minY = y;
}
if (y > maxY) {
maxY = y;
}
}
}
}
//TEGNER BOUNDING BOX TIL MONITOR
tv.fill(0);
if (found) {
tv.draw_line(minX, minY, maxX, minY, 1);
tv.draw_line(minX, minY, minX, maxY, 1);
tv.draw_line(maxX, minY, maxX, maxY, 1);
tv.draw_line(minX, maxY, maxX, maxY, 1);
sprintf(s, "%d, %d", ((maxX+minX)/2), ((maxY+minY)/2));
tv.print(0, 0, s);
}
tv.resume();
tv.delay_frame(2);
/*Serial.begin(9600);
Serial.print(xVektor);
Serial.print('t');
Serial.print(yVektor);
Serial.print('n');*/
}//SLUTT PÅ HOVEDLØKKE
There seem to be some sort of conflict, but we have no idea what it can be. We are kinda lost, and hope someone on here can give us some help!
April 25, 2014 at 3:19 pm #1914MichaelKeymasterI am guessing that M2 is the motor that does not work when the VE is being used?
The video library uses Timer1 to control all the timing. This means you cannot use pins 9 or 10 for PWM. You can still use pins 5,3,11 for PWM.
I would try this:
int E1 = 5; //M1 Speed Control
int E2 = 3; //M2 Speed Control
int M1 = 10; //M1 Direction Control
int M2 = 11; //M2 Direction ControlApril 25, 2014 at 3:47 pm #1915fphMemberOh.. We will try it out on Sunday. We came up with a backup plan of using one UNO for the tracking, and one for the motors, and just send the coordinates via serial, but hopefully it is this simple! Thanks for the swift reply Michael! 🙂
April 28, 2014 at 1:42 pm #1916fphMemberChanging the code to what you recomended, and pin outs accordingly, only helped partially. We got both motors working, but they ran at different speeds. Do you have any idea why that is? Now M1 was acting up. Direction control was ok, but the speed control was faulty. M2 seems to be working as intended.
We also tried to use 2 UNO’s, and send coordinates with serial, but we wont get that to work either. As soon as we implement the VE setup code it breaks down. We are using rx on the arduino with the VE stacked on it, and tx on the other arduino. And we have them connected via ground. The transmission works flawless as long as we are not implementing any of the VE setup code.
April 28, 2014 at 2:04 pm #1917MichaelKeymasterBasically, when you are doing video on an Arduino, you require exact timing. You can’t do serial communication at the same time. The TVout library comes with a polling version of serial (the pollserial library). Use that on the Arduino that is running the TVout code.
I am not sure why the PWM on one pin is causing different speed than the other. Perhaps you can just adjust it in software?
Bottom line is that it is difficult to do other things on an Arduino when you are generating a video signal.
April 28, 2014 at 3:37 pm #1918fphMemberSorry, the reason both motors worked was cause we had one of them connected to d2, not d3. So it got some values from the VE code. Only one motor works when we connect like this:
int E1 = 5; //M1_PWM
int E2 = 3; //M2_PWM
int M1 = 10; //M1_EN
int M2 = 11; //M2_ENSo our last hope seems to be to use two arduinos and transmit the coordinates from the one running the VE to the one running the motors, but we are not really sure how to do it with pollserial. We need to #include
only on the arduino running the TVout code? But not the arduino running our motors? Could you give us an example of what our code should look like on the transmitter and reciever end? April 28, 2014 at 3:55 pm #1919MichaelKeymasterSo PWM on pin 3 is not working? Hmm, it should.
pollserial is used just like Serial. Only use pollserial on the Arduino with the VE. The other Arduino just uses normal Serial.
This is the example sketch that comes with TVout:
#include
#include
#include
TVout TV;
pollserial pserial;
void setup() {
TV.begin(_NTSC,192,128);
TV.select_font(font6x8);
TV.println("Serial Terminal");
TV.println("-- Version 0.1 --");
TV.set_hbi_hook(pserial.begin(57600));
}
void loop() {
if (pserial.available()) {
TV.print((char)pserial.read());
}
}You will be limited in how much data you can transfer because thei pollserial implementation is only polling for data during the horizontal blanking interval. Hope this works for you.
May 1, 2014 at 6:17 pm #1924fphMemberWe made it work with two Arduino UNOs, and poll serial! Thanks for the help Michael 🙂
May 10, 2014 at 1:18 pm #1848fphMemberAnd here is a video of our final result http://www.youtube.com/watch?v=D4JH9kWmt-c&feature=youtu.be
May 10, 2014 at 3:53 pm #1849MichaelKeymasterI love it! That is a very awesome project.
-
AuthorPosts
- You must be logged in to reply to this topic.