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

RaspInLoop

Hello all,

I just came into something that might be interesting to simulate and debug applications using PI4J.  Have a look at RaspInLoop.  I am an IntelliJ user so I can’t test it.  Hopefully there will come something similar for IntelliJ.

Jan

Continue reading »

New Car Chassis

Hello all,

first of all I want to wish you all a very happy 2016.  Hope all your dreams may come true and mine of course.

During the Winter holidays I took the opportunity to order a new chassis for the Raspberry Pi Controlled Car.  The one I got was not good.  Pieces were missing or incorrect and that made it not as expected.  The package came from China and was cheap so I won’t complain.  It’s sometimes a risk we have to take.  Anyway, I did use that chassis to do my first developments and tests so it was not a waste of money.  Once the new chassis was there, I directly started setting it up and and let it drive.  You can see some pictures here under.  I am pretty satisfied I got it working.  I made a little interface in JavaFX with a couple of buttons : Forward, Backward, Left, Right and a speed slider.  That’s all I need for the moment in the interface.  As I said.  Very simple.  The interface is running on my laptop and it communicates via RMI towards my developments installed on the Raspberry Pi.  It is working well although I notice sometimes a lack of responsiveness.  Question is if my choice for RMI is the reason for that or not.  I haven’t taken the time to investigate if I could use for example a light webservice (REST) to speed up.  Anyway, the goal was to let it move and turn …  Now I need to do the finetuning when I have time.

IMG_2220 IMG_2221 IMG_2219

Continue reading »

Need for Spring ?

I have a setupCar method which initializes the inputs (individual motors)I use on my RPD (Raspberry Pi Driven) Car.  When I look at the code I notice this is not ideal. Too much hardcoded dependencies and this is not really something I want.  Imagine I would like to swtich pins because a pin broke,  …  I would have to modify the method and do a new build.  If I was using Spring I would only have to change the bean xml file and up we go.  I prefer to have some flexibility. As mentioned, Spring might bring the solution but I need to have a look at that and try to find out if I can configure the PI4J depencies in a Spring bean xml file. The source code as it is now, smells dirty.

See source of the method setupCar as it is now here under :

     public void setupCar() {
        input1 = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_02,
                "INPUT1",
                PinState.LOW);
        input2 = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_03,
                "INPUT2",
                PinState.LOW);
        input3 = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_05,
                "INPUT3",
                PinState.LOW);
        input4 = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_06,
                "INPUT4",
                PinState.LOW);
        leftWheel = new Wheel(0, input1, input2);
        rightWheel = new Wheel(4, input3, input4);
        wheelAxle = new WheelAxle(leftWheel, rightWheel);
        car = new TwoWheelDriveRaspyCar(wheelAxle);
    }

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 »