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

JavaFX

Hello, it has been a while since I last wrote something on my blog.  It doesn’t mean that I stopped but only that I didn’t have much time the last weeks.  But I did continue to fine tune the car movements.

During my developments of the RP Driven Car, I was looking for a way to interface with the car.  Just a small interface which I can use to make it go forward, backward and steer.   The key features for the car itself are developed but I need urgently a way to call them in an easy and flexible way so I can test drive the car.  My first thought was to use standard input an use the arrows to control the car.  Problem with the standard input is that each time you pushed an arrow you also have to push the enter to make the arrow input visible and readable from the stream.  So instead of pushing for example the up arrow to go forward I had to push the up and enter.  Which is not really flexible.  I was looking for a solution to deal with that and apparently there is none.  There were some external libraries who could probably do that but I am not in favor of so called exotic code that I would only use once.  Than I came to the id of having a little GUI that could do the trick.  Why not ?  Maybe a little more complicated because of the additional complexity but I am always open to try new things.  I have written applications with a GUI in the past (almost long time ago 🙂 ) but those were Web applications.  Now I mainly do developments in middleware where there is no need for GUI’s.  So I see this as an opportunity to have a look at the technical possibilities to write an interface which will interface with the RP to control the car.  I quickly came at JavaFX.  I have heared about it already several times and at last years DEVOXX conference there was a demo using JavaFX to connect with a Raspberry Pi which worked very well.  That is why I want to try this also out.  I’ll need some time to read about it and start some tryouts to find out how exactly I will do this.  I have not thought yet whether I will setup a webservice on the RP or interface via RMI.  Everything is open.  First I will focus on the simple interface.  It should look like the screenshot here under.  As I said.  Very simple to start with.

CarInterface

Jan

Continue reading »

PWM enable pins L298N

Hello readers,

Trying out pwm pins to control the speed of the dc motors was not an easy story.  WiringPi has a software driven pwm handler which is used via PI4J.  In fact WiringPi is a GPI Access C library.  For more information see WiringPi.  The software handler makes it possible to have pwm functionality on all GPIO data pins on the raspberry pi.  There are also hardware pwm pins but there are only a couple of those dedicated hardware pins.  I have chosen to go for the software handled pwm pins.  What worried me was that the pin for the enable pin was not like the ones for the input pins (between the 2 enable pins) on the L298N.  I managed to get it wired but was not really satisfied because it didn’t fit right.  The result was that I could not manage at all the speed of the dc motors using pwm.  Whatever I tried in my little test program, it did not work work on the dc motors.  Just on the moment I was about to test with the hardware pwm pins, I found out there was a jumper on the enable pin, covering 2 pins.  At first sight when turning the L298N upside down, one pin was connected to the enable and the other pin had no real connection.  But since I am not a microchip nor electronics expert, that could be a wrong impression.  I connected 2 pwm (software handled) pins from the raspberry pi with the enable pins on the L298N which fitted right this time.  And guess what.  It worked.  I was able to increase and decrease speed of the dc motors.  Just like mentioned on the WiringPi site.

Shortly the pin wiring.  I am using the Raspberry Pi B+.  The port numbering is described at GPIO Port Numbering.

GPIO 0 -> enable A, GPIO 4 -> enable B, GPIO 2 -> input 1, GPIO 3 -> input 2, GPIO 5 -> input 3, GPIO 6 -> input 4, the output pins are wired to the dc motors, the battery (I used a 8,4V) positive wire is wired to the +V12 pin, the 3,3V power pin (Raspberry Pi) is wired to the +5V pin.  I know it sounds not logical +12V connected to 8,4V and +5V connected to 3,3V but it worked.  I bet my motor will turn like mad when I put higher voltage battery on it.

Jan

l298njumper

Continue reading »

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 »