I am java developer and pi4j begginer. I am developing java app that can control servo (raspberry pi 4 model b)
the error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/pi4j/wiringpi/Gpio
at me.Olex7iMatix.CatBotSoftware.Main.main(Main.java:9)
Caused by: java.lang.ClassNotFoundException: com.pi4j.wiringpi.Gpio
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 1 more
JRE system library: JavaSE-1.8
the code
package me.Olex7iMatix.CatBotSoftware;
import com.pi4j.wiringpi.Gpio;
public class Main {
public static void main(String[] args) {
Gpio.pwmWrite(2, 50);
}
}
Edit: I just read the erorr message properly, you may need to just install the package, Installation guide
You are missing quite a lot of lines to get a servo to work with an RPi/Java.
You firstly need to tell the Pi which GPIO pin you are using and the output mode of said pin
com.pi4j.wiringpi.Gpio.pinMode({ENTER YOUR GPIO PIN HERE}, com.pi4j.wiringpi.Gpio.PWM_OUTPUT);
You also need to set the PWM Mode
com.pi4j.wiringpi.Gpio.pwmSetMode(com.pi4j.wiringpi.Gpio.PWM_MODE_MS);
com.pi4j.wiringpi.Gpio.pwmSetClock(192);
And then set the PWM Range
com.pi4j.wiringpi.Gpio.pwmSetRange(2000); // this may differ for your servo
Then you can set a loop do set the servo
while (true) {
com.pi4j.wiringpi.Gpio.pwmWrite({YOUR GPIO PIN}, 50);
Thread.sleep(10) // make this thread wait for 10 milliseconds
}
Related
I want to run an audio emulator of the genesis fm sound chip inside arduino. I plan to run it on a rp2040 which has plenty of power to run it
This is the emulator code:
https://github.com/nukeykt/Nuked-OPN2/blob/master/ym3438.h
And this is how Im trying to instantiate it, but I have errors. Can you point me on how to run the emulator?
#include "ym3438.h"
int buff = 0;
ym3438_t myChip;
void setup() {
}
void loop() {
buff++;
//this should advance the emultor clock
OPN2_Clock(myChip, buff);
//this should generate the sound samples
OPN2_Generate(myChip, buff);
}
Thanks!!
When trying to compile I get:
Compilation error: cannot convert 'ym3438_t' to 'ym3438_t*' for argument '1' to 'void OPN2_Clock(ym3438_t*, Bit16s*)'
I have tried putting* like:
OPN2_Clock(myChip*, buff*);
But it does not work either. Honesty Im not sure how to instantiate it
I am sending data from Arduino UNO R3 to nodeMcu esp8266. In that case sometime data are send properly but at sometime data are are not send by arduino or not get by nodemcu esp8266.Also tx light not blinks after i upload the code to the Arduiono.
enter code here
Code Uploaded to Arduino:
#include <SoftwareSerial.h>
#include <ArduinoJson.h>
SoftwareSerial s(10,11);
SoftwareSerial h(10,11);
int i=0;
void setup() {
// put your setup code here, to run once:
s.begin(9600);
Serial.begin(9600);
}
int f1=0;
int f2=0;
String st="sy";
void loop() {
f1=f1+1;
f2=f2+2;
// put your main code here, to run repeatedly:
StaticJsonBuffer <1000> bf;
StaticJsonBuffer <1000> rec;
JsonObject& root=bf.createObject();
JsonObject& receives=rec.parseObject(h);
if (receives==JsonObject::invalid())
{
Serial.println("no data from nodemcu");
root["data3"]="no data from nide";
}
else
{
root["data3"] = receives["data3"];
//st = (const char*)receive["data3"];
}
root["data1"]=f1;
root["data2"]=f2;
//root["data3"]=st;
if(s.available()>0)
{
root.printTo(s);
Serial.println("send");
}
else
{
Serial.println("NOt Available");}
//i=i+1;
//s.write(i);
delay(1000);
}
In your code thera are two reasons I can spot on the first look:
1 Never use delay in server client applications. Delay stops proccessing and inhibts communication. For more details how to avoid look at the blinkwithoutdelay built in Example in the Arduino IDE.
2. You use ArduinoJSON: This lib is absolute overkill for 99% of the applications it is used for. Don't get me wrong - the lib offers fantastic features, but if not needed this can be regarded as bloat-ware.
I wrote my own simple JSON coding/decoding (~250 lines of code) for a performant application using an Arduino as "Signal generator" and the ESP8266/ESP32 as a webserver. Communication between Arduino and ESPis time critical and so far it works over a year without problems,
I'm trying to implement communication between a seeeduino lorawan and the things network. The gateway is setup, however I've been unable to load the correct lorawan information onto the seeeduino.
I've been following the tutorial from their website: http://wiki.seeedstudio.com/Seeeduino_LoRAWAN/
The seeeduino does connect and I can upload code onto the seeeduino to read and print sensor data via serial, so the IDE settings, like board should be correct.
Problem 1: library LoRaWan.h is not known
Problem 2: When using a different Beelan Lorawan library, the library import works, but commands such as lora.getversion, lora.setid, etc. cause an error, because they don't exist.
So the main question really is, how to I let the seeeduino know, which AppSKey, DevEUI, AppEUI, etc. it should use?
#include <LoRaWan.h>
void setup(void)
{
Serial.begin(115200);
lora.init();
memset(buffer, 0, 256);
lora.getVersion(buffer, 256, 1);
SerialUprint(buffer);
memset(buffer, 0, 256);
lora.getId(buffer, 256, 1);
Serial.print(buffer);
// void setId(char *DevAddr, char *DevEUI, char *AppEUI);
lora.setId(NULL, "12409E2345695432", "70B3D57EF0006593");
// setKey(char *NwkSKey, char *AppSKey, char *AppKey);
lora.setKey(NULL, NULL, "47BDA77B6D7B4DDA7DC182E54295FE4E");
}
void loop(void)
{
}
The problem was with the newer 1.5.6 board version. Reverting to board version 1.3 of Seeed SAMD Boards installed the missing LoRaWaN library and allowed for a successfull setup of the lorawan components.
When I try to use rosserial to communicate with an Arduino to control the MX-64 motor, every time I use rostopic pub to send a message, it will give me this error:
"Mismatched protocol version in packet: lost sync or rosserial_python is from different ros release than the rosserial client "
If I remove the Dynamixel.move(X_SERVO_ID,rollint); function in the code or don't send any information though ROS, there will be no error. I tried all the rosserial examples, all of them are working just fine without any error.
The weird thing is even if it gives me an error, the program is still working. Every time I send a message, the DYNAMIXEL motor will start moving.
#if (ARDUINO >= 100)
#include <Arduino.h>
#else
#include <WProgram.h>
#endif
#include <ros.h>
#include <std_msgs/Int8.h>
ros::NodeHandle nh;
#include <Dynamixel_Serial.h> // Library needed to control Dynamixal servo
#include <sensor_msgs/Imu.h>
#define X_SERVO_ID 0x01 // ID which we will be set in Dynamixel too
int rollint = 0;
void motor_cb(const std_msgs::Int8& cmd_msg) {
rollint = ((1.00*(90-cmd_msg.data))/360)*4095;
Dynamixel.move(X_SERVO_ID,rollint);
}
ros::Subscriber<std_msgs::Int8> sub("MX_Motor", motor_cb);
void setup() {
delay(100); // Give time for Dynamixel to start on power-up
nh.initNode();
nh.subscribe(sub);
}
void loop(){
nh.spinOnce();
delay(1);
}
It looks like your Dynamixel servo is hooked up to the same serial port that you use to communicate with the rosserial server. In many Arduino boards like the Uno the hardware serial port (where your Dynamixel is hooked up) is connected to a USB serial converter (which connects ROS via USB).
You need to connect your Dynamixel to a different hardware (or software) serial on your Arduino and initialize it with Dynamixel.begin(Stream&) (Dynamixel_Serial.h#L162), where Stream& is that hardware / software serial.
I'm facing problem with sending AT Commands using Arduino Uno. I've written a small program (link below) to set up a server. I need to send data to Atmega from my laptop using Wifi module ESP8266. Everything would be fine if the entire program would do at once at the moment I need to comment and uncomment (adding and removing double slashes) every line of AT code, because only one AT command executes in a single compilation.
It seems like the program gets stuck somewhere in the while-loop (even on the module, I can see that blue diode stops blinking). I think that I've done something wrong in code and I would appreciate any help.
#include <SoftwareSerial.h>
SoftwareSerial espmod(2, 3);
void commands(String cmd, int waittime);
void setup(void) {
Serial.begin(9600);
espmod.begin(9600);
while (!Serial) {;}
commands("AT+GMR\r\n", 1000);
commands("AT+RST\r\n", 500);
commands("AT+CWMODE=1\r\n", 500);
commands("AT+CWJAP=\"SSID\",\"PASS\"\r\n", 4000);
commands("AT+CIPMUX=1\r\n", 500);
commands("AT+CIPSERVER=1,333\r\n", 500);
commands("AT+CIFSR\r\n", 500);
}
void loop() { // run over and over
}
void commands(String cmd, int waittime) {
espmod.print(cmd);
delay(waittime);
while(espmod.available()) {
char val = espmod.read();
Serial.write(val);
}
}
Here's the screen:
Version:
AT Version: 0.21.0.0
SDK Version: 0.9.5
Connections:
ESP
VCC -- 3,3 V (external source)
GND -- GND -- Arduino GND
RX -- TX (Arduino pin 3)
TX -- RX (Arduino pin 2)
CH_PD -- 3,3 V
RST -- 3,3 V
EDIT:
I've been fighting with this for couple of days, still without solution, but today it worked finally, but only once (after reseting power supply it's still the same) ! I could've seen all commands doing on SerialMonitor, so there is everything fine with code and i guess there is something wrong with esp module. As far as i can get only one AT command sent and executed in a single compilation, is it possible that 0,5 A current i provide to the module is not enough? Can module be out of the memory ? Is there any way to see SoftwareSerial monitor (is there anything like that)?
There is an unnecessary loop in command function. Let the arduino handle the loop for you. Also it is better to try with different delay parameters, maybe you can decrease some. Here the code I offer :
void loop() {
while (espmod.available()){
String result = espmod.readStringUntil('\n');
Serial.println("AT result : " + result);
}
}
void commands(String cmd, int waittime) {
espmod.print(cmd);
delay(waittime);
}