

Here was my code not using PWM using pins that had worked fine on the avoidance bot: I still don't know the correct command for PWM to control the speed? So maybe when in i2C mode you can't use PWM pins as standard OUTPUTS to the 'in' pins on the L298N? I then amended the code and changed the wiring to use non PWM pins for the L298N inputs and a PWM for the L298N en pin.įirst I tried using a PWM command with no joy, then I tried just to set the L298N en pin to High and when I ran the code Ta Da, the motor span :-) Pin 3 is also PWM so maybe setting the status of this pin to OUTPUT and High makes it PWM only? Then I checked the pinouts again for the Nano, looking at this page: When I looked at the pin status being returned, instead of High it showed a status of P?

I then tried a 470ohm resister and got the same results. When I connected up an LED using a 1K resistor connected to pin 3 on the Nano, the LED blinked very momentarily and very dim. What I am having trouble with is using PWM commands and reading pin status (I keep getting a key error). I have also managed to (finally) spin the motor connected to the L298N again using a Python command on the Rapsberry Pi.Īt first I was having no joy but found that this was because I had been using some of the the Nano PWM as OUTPUTS, when using Sketch without the Pi via i2C on the original bot this was not a problem but when using i2c it seems it may be? I have successfully interfaced the Arduino as Slave using i2C and have managed to blink the onboard LED using python on the raspberry Pi.

I am now trying to add a raspberry Pi connected via i2C to control the motors through the Nano, run a Webcam and stream video to a web page that will also be used to control the robot. Print("please enter the defined data to continue.I have successfully built a collision avoidance robot using an Arduino Nano AtMega328, HC-SR04 Sensors, 9gMicro Servo (for scanning) and 2 x DC Motors connected via an L298N Motor Driver. Print("r-run s-stop f-forward b-backward l-low m-medium h-high e-exit") Print("The default speed & direction of motor is LOW & Forward.") When I type "s" it stop for half a sec or less then continue to run. I tried to make it stop by setting the duty cycle to zero which works for me, but I trying to find out why it does not turn off when I set both GPIO to LOW to stop it. It also turn on even before I run the code. Everything works except the motor does not stop when I click "s". I m trying to control the speed and to turn off/ON a small motor using python in raspberry pi.
