User avatar
freedomotic
Posts: 154
Joined: Sat Apr 21, 2012 3:59 pm
Location: Italy
Contact: Website

Re: Pi4J - A Java library to interface with the Raspberry Pi

Fri Dec 14, 2012 6:14 pm

Hi Robert,
I'm working on a modified version of your SerialExample.java.
I followed all the instructions to disable the console.
My code sends ome ascii chars to communicate with a relay board.
Here an example
serial.write('a');
serial.write('A');
serial.write('b');
serial.write('B');

a switchs on a relay, A switch off and so on
But when I run the code it shows on dfferent rows
m
M
n
N
and it doesn't show anything.
The board requires a 9600 baud rate. I set it in the java code. Can it be this the problem?
Thanks
Mauro
Freedomotic Open IoT Framework
http://freedomotic.com

User avatar
savageautomate
Posts: 225
Joined: Thu Aug 16, 2012 3:20 pm
Location: USA
Contact: Website

Re: Pi4J - A Java library to interface with the Raspberry Pi

Fri Dec 14, 2012 9:13 pm

Hi Mauro,

Not sure I have personally tested the char API method, there could be a bug in it. I have successfully used the string input arguments in my projects. Try changing the input chars to strings and see if it makes a difference. I'll test with chars later tonight.

Once you get it working, you may want to consider creating a GpioProvider if you are controlling pin states on an external board/device. Check out this example where I use an Olimex AVR-IO-M16 relay board and it uses serial ASCII commands to control the relays:
https://github.com/Pi4J/pi4j/tree/maste ... ion/olimex

And here is the consumer example code:
https://github.com/Pi4J/pi4j/blob/maste ... ample.java

Thanks, Robert
Robert Savage | Follow me @savageautomate
http://www.pi4j.com | http://www.pislices.com
http://www.savagehomeautomation.com

User avatar
savageautomate
Posts: 225
Joined: Thu Aug 16, 2012 3:20 pm
Location: USA
Contact: Website

Re: Pi4J - A Java library to interface with the Raspberry Pi

Sat Dec 15, 2012 3:43 am

Hi Mauro,

I tested the serial communication from Pi4J tonight sending characters using the send(char) method and the exact characters you referenced in your example and it seems to be working correctly. I am getting the correct characters in a terminal software connected via serial cable and using 9600,N,8,1 baud rate and communication settings.

I tested using 0.0.4-SNAPSHOT, but that code really has not changed since it was first implemented. So I think something else must be going on.

Also, take a look at this blog article and make sure that the OS use of the port is completely disabled.
http://www.savagehomeautomation.com/pro ... l#software

Thanks, Robert
Robert Savage | Follow me @savageautomate
http://www.pi4j.com | http://www.pislices.com
http://www.savagehomeautomation.com

User avatar
freedomotic
Posts: 154
Joined: Sat Apr 21, 2012 3:59 pm
Location: Italy
Contact: Website

Re: Pi4J - A Java library to interface with the Raspberry Pi

Sat Dec 15, 2012 8:00 am

Hi Robert
thanks for support.
The board has a simple characters protocol.
With python libraries it works well:
here an example

Code: Select all

python
import serial
ao = serial.Serial('/dev/ttyAMA0',9600,timeout=0)
ao.write('a')
ao.close()


I followed your instructions and with dmesg I see the port is recognized. The string is
ttyAMA0 is a PLOII rev.3

Regards
Mauro
Freedomotic Open IoT Framework
http://freedomotic.com

User avatar
freedomotic
Posts: 154
Joined: Sat Apr 21, 2012 3:59 pm
Location: Italy
Contact: Website

Re: Pi4J - A Java library to interface with the Raspberry Pi

Sun Dec 16, 2012 10:02 am

Hi Robert
is there a way to make sure that the OS use of the port is completely disabled?
Mauro
Freedomotic Open IoT Framework
http://freedomotic.com

User avatar
savageautomate
Posts: 225
Joined: Thu Aug 16, 2012 3:20 pm
Location: USA
Contact: Website

Re: Pi4J - A Java library to interface with the Raspberry Pi

Sun Dec 16, 2012 4:29 pm

freedomotic wrote:Hi Robert
is there a way to make sure that the OS use of the port is completely disabled?
Mauro
Hi Mauro,

The only thing I know to do is comment out the line in the "/etc/inittab" file that references ttyAMA0 and in the "/boot/cmdline.txt" file remove the "console=ttyAMA0,115200 kgdboc=ttyAMA0,115200" part.

Not that it should matter, but which Pi are you using Rev 1, Rev 1.1, Rev 2, 256/512mb? I can test it again on the exact platform if I have one on hand.

-Robert
Robert Savage | Follow me @savageautomate
http://www.pi4j.com | http://www.pislices.com
http://www.savagehomeautomation.com

ilangeeran
Posts: 2
Joined: Tue Apr 22, 2014 10:45 am
Location: India
Contact: Website

Re: Pi4J - A Java library to interface with the Raspberry Pi

Thu Mar 12, 2015 5:41 am

Whenever i try to unprovision a pin, it says that symbol method unProvisionPin() is not found Any suggestions to get rid of this would be helpful. Thanks in advance.

User avatar
savageautomate
Posts: 225
Joined: Thu Aug 16, 2012 3:20 pm
Location: USA
Contact: Website

Re: Pi4J - A Java library to interface with the Raspberry Pi

Thu Mar 12, 2015 1:08 pm

ilangeeran wrote:Whenever i try to unprovision a pin, it says that symbol method unProvisionPin() is not found Any suggestions to get rid of this would be helpful. Thanks in advance.
ilangeeran,
Please make sure you are using the latest 1.0-SNAPHOT build of the Pi4J library. That method may not have existed in earlier versions. http://pi4j.com/download.html

You can see the method exists here on the interface in the "develop" brach which is the branch for the 1.0-SNAPSHOT builds:
https://github.com/Pi4J/pi4j/blob/devel ... .java#L151

Also please note the case of method name -- it is case sensitive.

Code: Select all

    void unprovisionPin(GpioPin... pin);
Thanks, Robert
Robert Savage | Follow me @savageautomate
http://www.pi4j.com | http://www.pislices.com
http://www.savagehomeautomation.com

Return to “Other programming languages”