Android Question PCDuino

luigi.crocella

Member
Licensed User
Longtime User
Hi Erel and all developers

I would like to use B4A to develop apps to run in a "PcDuino" running android 4.0.4 .

This way I can access I/O ports, PWM, serial, without external hardware.

The ports are accessed from Java in this way:
---------------------------------------------
package pcduino.test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
/**
* A class to access and manage the GPIO pins of a pcDuino
*
* @author Mohammad Adib
*/
public class GPIO_Pin {
/**
* Initialize variables
*/
private String modeURI = "/sys/devices/virtual/misc/gpio/mode/";
private String statusURI = "/sys/devices/virtual/misc/gpio/pin/";
private int pin = 0;
public static final String HIGH = "1", LOW = "0", INPUT = "0", OUTPUT = "1", INPUT_PU = "8";
/**
* Constructor
*/
public GPIO_Pin(int pin) {
// Finalize file paths
modeURI += "gpio" + pin;
statusURI += "gpio" + pin;
this.pin = pin;
}
/**
* @return the specified pin number
*/
public int getPin() {
return pin;
}
/**
* Overrides the default directory for pins and their mode/state (sys/devices/virtual/misc/gpio/)
*
* @param uri
*/
public void overrideURI(String uri) {
modeURI = uri + "mode/gpio" + pin;
statusURI = uri + "pin/gpio" + pin;
}
/**
* Sets the mode of the pin to a user-defined String
*/
public void setMode(String mode) {
writeToFile(getModeURI(), mode);
}
/**
* Sets the state of the pin to a user-defined String
*/
public void set(String state) {
writeToFile(getStatusURI(), state);
}
/**
* Sets the state of the pin to HIGH
*/
public void setHIGH() {
writeToFile(getStatusURI(), HIGH);
}
/**
* Sets the state of the pin to LOW
*/
public void setLOW() {
writeToFile(getStatusURI(), LOW);
}
/**
* Sets the mode of the pin to INPUT
*/
public void setModeINPUT() {
writeToFile(getModeURI(), INPUT);
}
/**
* Sets the mode of the pin to OUTPUT
*/
public void setModeOUTPUT() {
writeToFile(getModeURI(), OUTPUT);
}
/**
* Sets the mode of the pin to INPUT PULL UP
*/
public void setModeINPUT_PU() {
writeToFile(getModeURI(), INPUT_PU);
}
/**
* @return the path to the mode file of the pin
*/
public String getModeURI() {
return modeURI;
}
/**
* @return the path to the state file of the pin
*/
public String getStatusURI() {
return statusURI;
}
/**
* @return the current mode of the pin
*/
public String getPinMode() {
try {
BufferedReader reader = new BufferedReader(new FileReader(getModeURI()));
String data = reader.readLine();
reader.close();
return data;
} catch (IOException e) {
}
return "";
}
/**
* @return the current status of the pin
*/
public String getPinStatus() {
try {
BufferedReader reader = new BufferedReader(new FileReader(getStatusURI()));
String data = reader.readLine();
reader.close();
return data;
} catch (IOException e) {
}
return "";
}
/**
* Writes the data to the specified GPIO pin file
*
* @param URI that path of the mode/state file of the pin
* @param data the data to write to the file
*/
private void writeToFile(String URI, String data) {
try {
// delete the file
File file = new File(URI);
file.delete();
// recreate it
File newFile = new File(URI);
newFile.createNewFile();
// write the specified data to it
try (FileWriter writer = new FileWriter(URI)) {
writer.write(data);
// close the file to apply the change
writer.close();
System.out.println("Wrote " + "\"" + data + "\" to " + URI);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
----------------------------------------------------------------------

Can you help me to use b4a to do this?
Thanks
 

luigi.crocella

Member
Licensed User
Longtime User
Thanks Erel,
I'll try now to make a translation of the code in B4A . The goal is not only to put a pin high or low , or read it, but also get to use the ADC , the pwm , implement I2C, use the uart serial communication , etc...
I have the code in C, Python , and Java who does these things , and I think the philosophy is always the same : to read and write to files that make up an API for the operation ... the translation becomes more serious .... I'll try and I'll keep you informed .

There is a whole world of developers of embedded systems, to which I belong , which opens up the possibility to use Android as an operating system for their hardware. So have a software development system as B4A to develop their work would be a great opportunity, especially for the creation of GUI to manage all devices and sensors connected to the ' motherboard '...and the possibilities offered by the excellent management of Internet protocols offered by B4A to implement distributed remote control, monitoring and management of them (devices and sensors).

Thanks again for your fast and valuable advices.

(I hope my english is understandable)
 
Upvote 0

salim safran

Member
Licensed User
Longtime User
as far PCduino, I have read in their web site that they removed the support of the device tree for PWM under android GPIO in later flashes, , I contacted them and showed great concern to resolve this issue, i am waiting to hear back from them as being informed. no doubt PCduino is a perfect compact super DAQ embedded system with great applications if we can see examples for PCduino with PWM examples in B4A. I just bought beaglebone, RaspBerryPI and Pcduino for testing, some how I see PCduino winning within it's resources and flashes till now.
 
Upvote 0

Tom Christman

Active Member
Licensed User
Longtime User
Stay tuned.....If I had to guess, I'd say Erel and his RaspBerryPi and B4J will probably win the Race!!!! (If it hasn't won already)....See RaspBerryPi GPIO Controller
 
Upvote 0

salim safran

Member
Licensed User
Longtime User
the only one who can make a real difference is Arduino TRE ( somehow partially beaglebone TI ) only and only if it has direct PWM and Analogs (under device tree for Linux and android) not just through the serial atmel MCU on board, so we can do high speed sampling and PWM control on the same board, till now the only one who can do interesting industrial control application in single board according to my current knowledge is PCduino and maybe beaglebone but sometime from now, yes the PI b4j will no doubt shift most developers and hobbyists of Raspberry PI to basic4android great tools. I would love to see basic4android supporting PCduino as it is ready platform and can be perfected as standalone board. it is going to be refreshing to see Arduino's great minds cooperate with this basic4android as it will take Linux industrial and control development to a newly higher market in away I see it as a hope we no longer use the life consuming Microsoft OS hacking systems in our life. I wonder where is Google till now and why sleeping away from this great coming industry. TI came up with creative processor behind beaglebone and other floating point processor with real cost effective solutions like the genius of all the tivia mcu , Intel came up with an embarrassing board called Galileo does not correlate with our expectations from such technology provider and Microsoft with the gadgetsteer as usual limited platform but nothing from Google till now as we always look forward to see high expectations and innovations from them to serve, support and share knowledge on earth. I would love to see a board similar to Arduino TRE or UDOO but with TI Tivia floating point mcu so we can unlock the limitations of mcu DSP applications with affordable IDE tools to all. also the possibility to see Vortex86 processors as true x86 architecture with Linux /android combined with ARM ones and floating point mcu all in a single board will be opening all the doors to take custom user applications to the endless opportunities.
 
Last edited:
Upvote 0
Top