Home » Java » Archive by category "Pi4J" (Page 4)

Pulse Width Modulation (PWM)

Hello folks,

I found a nice example on PWM in the PI4J project.  See PWM Example.  I tried it on my Raspberry PI B+.  I wired a little circuit with a led and tried it out.  It worked smoothly.  The led faded on and off which was the goal.  I had been trying this on my car based on the javadoc but it was not working so I needed a plain simple example to see how this PWM works and just to be sure it does work on my Raspberry Pi. Seeing this example immediately rang a bell why it was not working on the car.  I had configured and set the pulse in the enable pin but a little further in my application the enable pin was set high which I guess overruled the PWM setting.  I know what to change now and try it out.

Continue reading »

Raspberry Pi Controlled Car : turn

Hello readers,

I managed to make my RPC (Raspberry Pi Controlled) Car turn.  But the result was not what I expected.  I had this great idea to let the front wheels turn in opposite direction for a fraction of a second.  Well how do I say.  The result was not what I hoped it to be.  The car turned but it turned in such a way that the Raspberry Pi and powerbank were literally thrown off the car and almost all cables were disconnected from the connectors.  What happened was that the turn was so violent that the car did a spin of 360°.  Not exactly what I wanted.  Even only turning 1 wheel without the other turning in opposite direction did not solve the issue.  I saw that the speed of the DC Motor was too violent in case the car is turning.  So I started reading and googling around and finally found that the L298N controller is able to control the speed of the dc motors.  What needs to be done is connect the enable inputs to an PWM (Pulse Width Modulation) cabable output from the Raspberry Pi.  For more information see the following link : PWM L298N.  I have understood that this is possible on Raspberry Pi and PI4J makes pwm available on all GPIO pins.  But as a former colleague of me always said : “The proof of the pudding is in the eating”.  I will go into detail on this and modify my program and make it support pwm.  I am curious.  I will let you know more as soon as I have done my first tests.  Maybe than will be a good time to package my code for the car and put it on GitHub.

Jan

Continue reading »

Raspberry Pi Controlled Car : moving on

Hi folks,

after having assembled the car it was now time to move on.  The goal is to have a car that drives, not a car that collects dust. The last week I have been coding to get a nice set of functions to get the my car moving.  Not so long ago I already developed a piece of code to let a DC motor turn a wheel.  That experience I integrated in the current developments.  I had a strong limitation and that was the current I needed for my Raspberry Pi.  It was clear I needed a powerbank.  After some investigation I finally decided to order the XB101 Xtorm Power Bank Trip 9000.  I was a little worried about the 2.5 A current output from the powerbank knowing the Raspberry Pi needs maximum 2A.  Finally after a lot of googling came on a forum where somebody said that the Raspberry Pi only takes the amount current that it needs.  Another thing I was worried about was the 5V output.  I know the Raspberry Pi needs 5V but I was wondering what in case the powerbank was not able to give the full 5V and due to some loss (USB cable) only able to give 4.8V for example.  So I was looking for a powerbank with an output of 5.25V but didn’t find any.  Anyway I found some tests where the output was  also 5V and did not gave any issues for the Raspberry Pi.  After too much time of investigating and looking for information I finally ordered the powerbank yesterday evening.  And this morning it was already delivered.  My god what a great service.  I really hate running around in big stores looking for what I need.  I really prefer the internet.  It so much easier.  Now coming back on my developments.  I am now able to let the car move forward and backward by controlling 2 DC motors.  Let’s say  2-wheel drive.  Next step is making it able to turn.  There I will have to do some magic controlling the 2 DC motors to get this done.  Still thinking about the algorithm.  I am seeing a couple of possibilities but I have to test it first.

Before I forget.  I had to remove the cobbler and the breadboard because they were a real pain to get everything wired and placed on the car which was a big problem because the breadboard and cobbler took some place and were limiting me in my work.

About the source-code.  I will only publish once I have something that is presentable.  If you need the source about my current experiments earlier, please let me know and I can send it.

Jan

Raspberry Pi Controlled Car

Raspberry Pi Controlled Car

Continue reading »

Raspberry Pi Controlled Car : First Milestone

Hello folks,

I finally took the time to setup the car chassis which I got from China.  When I opened the package a while ago I immediately saw a bad surprise and that was the fact that I did not receive all correct pieces.  The 2 blades for the chassis are identical and that should not have been the case because first blade was especially for attaching the DC motors and the second for pieces on top of the chassis.  I had to use my creativity to get around that.  Another point were the pieces for attaching the DC motors to the blade which were not all the correct ones.  Anyway.  I managed to get the chassis set up.

As a first step I wanted to get one wheel turning forward and backward using Raspberry Pi, L298N (motor controller) and DC-motor.  See the result here : Raspberry Pi Controlled Car  Next step is getting the second front wheel to turn but than I will have to make sure they work together to get my car driving and turning in a controlled way.

Needless to say I used Java and Pi4J to do this.  I have not yet pushed the sources to github but I will as soon as I cleanup the test application.

 

Jan

 

Continue reading »