Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ The following table the currently supported devices within this project:
| Sensor | 1-Wire | (1) | [DHT22 Temp/Humidity sensor](src/main/java/com/pi4j/devices/dht22/README.md)
| Sensor | | | [HC-SR04 Ultrasonic Sensor](src/main/java/com/pi4j/devices/hcsr04/README.md)
| Sensor | I2C | (1) | [MPL3115A2 Temp/Pressure/Altitude device](src/main/java/com/pi4j/devices/mpl3115a2/README.md)
| Servo | PWM | | [SG90 180 degree servo device](src/main/java/com/pi4j/devices/sg90/README.md)


### Notes:
Expand Down
2 changes: 1 addition & 1 deletion assets/runDHT22.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env bash
java -classpath ./*:../classes com.pi4j.devices.dht22.DHT22_App $@
java -classpath ./*:../classes com.pi4j.devices.dht22.DHT22_App $@
4 changes: 4 additions & 0 deletions assets/runSg90.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash


java -classpath ./*:../classes com.pi4j.devices.sg90.Sg90App $@
89 changes: 50 additions & 39 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<java.version>25</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<maven-jar-plugin.version>3.2.0</maven-jar-plugin.version>
<maven-jar-plugin.version>3.2.0</maven-jar-plugin.version>
<maven-source-plugin.version>3.3.1</maven-source-plugin.version>
<maven-bundle-plugin.version>5.1.9</maven-bundle-plugin.version>
<maven-javadoc-plugin.version>3.3.2</maven-javadoc-plugin.version>
Expand All @@ -33,9 +33,9 @@

<!-- DEPENDENCIES VERSIONS 2.0.3 -SNAPSHOT -->
<slf4j.version>2.0.17</slf4j.version>
<pi4j.version>4.0.1</pi4j.version>
<!--pi4j.version>5.0.0-SNAPSHOT</pi4j.version -->

<pi4j.version>5.0.0-SNAPSHOT</pi4j.version>
<pi4j-driver.version>2.0.0-SNAPSHOT</pi4j-driver.version>
<!-- BUILD PLUGIN VERSIONS -->
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
<maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
Expand All @@ -60,6 +60,17 @@
<name>Sonatype OSS Maven2 Repository</name>
<url>https://mvnrepository.com/artifact/org.apache.felix/maven-bundle-plugin</url>
</repository>
<repository>
<id>sonatype-snapshots</id>
<name>Maven Central Snapshots</name>
<url>https://central.sonatype.com/repository/maven-snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>sonatype-oss-staging</id>
<name>Sonatype Open Source Maven Repository</name>
Expand All @@ -84,27 +95,27 @@
<artifactId>pi4j-plugin-gpiod</artifactId>
<version>${pi4j.version}</version>
</dependency-->
<!--dependency>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-plugin-linuxfs</artifactId>
<version>${pi4j.version}</version>
</dependency-->
<!--dependency>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-plugin-linuxfs</artifactId>
<version>${pi4j.version}</version>
</dependency-->
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>5.12.1</version>
</dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>5.12.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
</dependency>
<!-- include Pi4J Core -->
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
</dependency>
<!-- include Pi4J Core -->
<dependency>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-core</artifactId>
Expand All @@ -119,15 +130,15 @@
<!--- log4j - version 2 -->

<!-- include Pi4J Plugins (Platforms and I/O Providers) -->
<dependency>
<!--dependency>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-plugin-raspberrypi</artifactId>
<version>${pi4j.version}</version>
</dependency>
</dependency-->
<dependency>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-drivers</artifactId>
<version>1.1.1-SNAPSHOT</version>
<version>${pi4j-driver.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
Expand Down Expand Up @@ -190,19 +201,19 @@
</plugin-->

<!-- INCLUDE SOURCE JAR -->
<plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven-source-plugin.version}</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<version>${maven-source-plugin.version}</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>

<!-- INCLUDE JAVADOC JAR -->
<!--plugin>
Expand Down Expand Up @@ -282,7 +293,7 @@
<argument>--module-path</argument>
<argument>${project.build.directory}/distribution</argument>
<argument>--module</argument>
<!-- <argument>com.pi4j.devices.tca9548/com.pi4j.devices.tca9548.SampleTca9548App</argument> -->
<!-- <argument>com.pi4j.devices.tca9548/com.pi4j.devices.tca9548.SampleTca9548App</argument> -->
<argument>com.pi4j.devices.mcp23008/com.pi4j.devices.mcp23008.Mcp23008App</argument>
</arguments>
</configuration>
Expand Down Expand Up @@ -373,7 +384,7 @@
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>${maven-antrun-plugin.version}</version>
<executions>
<executions>
<execution>
<id>copySH</id>
<phase>install</phase>
Expand Down Expand Up @@ -460,4 +471,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
2 changes: 1 addition & 1 deletion src/main/java/com/pi4j/devices/mcp4725/MCP4725App.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public class MCP4725App {

static void main(String[] args) {
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "OFF");
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "INFO");

Logger logger = LoggerFactory.getLogger(MCP4725App.class);
logger.trace(">>> Enter: init");
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/pi4j/devices/mcp4728/MCP4728App.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
public class MCP4728App {

static void main(String[] args) {
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "OFF");
System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "iNFO");
Logger logger = LoggerFactory.getLogger(MCP4728App.class);
logger.trace(">>> Enter: init");

Expand Down
60 changes: 60 additions & 0 deletions src/main/java/com/pi4j/devices/sg90/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# SG90 servo motor

https://www.scribd.com/document/420327552/Servo
https://www.friendlywire.com/projects/ne555-servo-safe/SG90-datasheet.pdf

These devices do not have a customary DataSheet. Most servo devices provide limited specifications
for required pulse width, they just say 1 - 2 millisecond.

The SG90 defines a specific PWM interface and exactly how the PWN signal
controls the servo. There are many different manufacturers of the SG90 servo.
The pulse width required for setting the servo at 0 degrees or 180 degrees varies by
manufacturer. The driver by default uses the pulse width timing as
(low)1000 - (high)2000 microseconds. The user of this example application can change these defaults when first
invoking the program.

If the servo does not rotate to the desired position, Example: to rotate closer to the 0 degree
point reduce the -low argument, to rotate closer to the 180 degree point increase the
-high argument. The -low -high change should be balanced or 90 degree will not properly align.
Meaning if you reduce the -low by 200, you should increase the -high by 200, or visa-versa.



Connections between the SG90 servo and the Raspberry Pi
SG90 Pi
Grey/Brown Ground
Red 5V
Yellow GPIO18 config.sys contains dtoverlay=pwm-2chan
Comment thread
taartspi marked this conversation as resolved.



1. ./mvnw clean package
2. cd target/distribution
3. ./runSg90.sh args

-c channel (default 2) set the channel, depending on config.txt 1 2 3 4
-low double pulse width for 0 degree microseconds
-high double pulse width for 180 degree microseconds
-q quit
-h help

./runSg90.sh begins execution of the application, you then enter the desired servo degree of rotation.
Then continue entering the requested degree value, or any key will exist the program.

Set ouput shaft at 120 degree
./runSg90.sh
120

Driver defaults to 0 degree requires a 1000 micro second pulse, 180 degree requires a 2000 microsecond pulse
If your servo requires different pulse widths

Set low high pulse widths, then set output shaft at 120 degree
./runSg90.sh -low 600 -high 2400
120

My Sg90 aligns correctly with these values
./runSg90.sh -low 550 -high 2450

If your configuration uses a channel other than 2
./runSg90.sh -c 1
120
Loading
Loading