Closed lobsteroh closed 8 years ago
Yes, this issue is the same as #44
I guess I will go with option one and change this line
Hopefully it should work now
looks like i need to create and send low level DigitalWriteMsg to figure out exactly where the thing goes wrong ... still only getting 2.5V on DigitalPin 8 with DigitalState.HIGH
Ok... Did you properly set the mode of that pin before setting it to High?
Hi Brice, I understand that you want to include the type checking by declaring enums but it realy limits testing when the behavior is not what it is meant to be. on my copy of JArduino i have added the constructor
public DigitalWriteMsg(DigitalPin pin, byte byteValue) {
setCommandID(JArduinoProtocol.DIGITAL_WRITE);
setByteValue(pin.getValue());
this.pin = pin;
setByteValue(new Byte(byteValue));
//this.value = byteValue;
}
and in AbstractJArduino
public void digitalWrite(DigitalPin pin, byte value) {
// Create message using the factory
FixedSizePacket p = JArduinoProtocol.createDigitalWrite(pin, value);
// Send the message on the serial line
serial.receiveMsg(p.getPacket());
}
so now i can send specific byte values to test digitalWrite(). This is the test class i am using where you can just comment
import org.sintef.jarduino.DigitalPin;
import org.sintef.jarduino.JArduino;
import org.sintef.jarduino.PWMPin;
public class ArduinoTestWrite extends JArduino {
//static Object outPin = PWMPin.PWM_PIN_11;
static Object outPin = DigitalPin.PIN_11;
static byte onVal = (byte)127;
public ArduinoTestWrite(String port) { super(port); }
@Override
protected void setup() {}
@Override
protected void loop() {}
public static void main(String[] args) {
try {
String serialPort = "/dev/tty.usbmodem1421";
ArduinoTestWrite arduino = new ArduinoTestWrite(serialPort);
arduino.runArduinoProcess();
Thread.sleep(2000);
if (outPin instanceof PWMPin)
arduino.analogWrite((PWMPin)outPin,onVal);
else if (outPin instanceof DigitalPin)
arduino.digitalWrite((DigitalPin)outPin,onVal);
System.out.println("Turning on LED with byte value: " + onVal);
Thread.sleep(1000);
arduino.stopArduinoProcess();
} catch (Exception e) { e.printStackTrace(); }
}
}
Switching PWMPin to the DigitalPin line reduces output to half. I am puzzled where the problem sits ... suggestions?
you got it. Yes, setting pinMode makes all the difference, but it has to happen at a point when the arduino is already listening. This version now works like a charm. Any byte value other than 0 will turn on the DigitalPin full steam...
import org.sintef.jarduino.DigitalPin;
import org.sintef.jarduino.JArduino;
import org.sintef.jarduino.PWMPin;
import org.sintef.jarduino.PinMode;
public class ArduinoTestWrite extends JArduino {
//static Object outPin = PWMPin.PWM_PIN_11;
static Object outPin = DigitalPin.PIN_11;
static byte onVal = (byte)127;
public ArduinoTestWrite(String port) {
super(port);
}
@Override
protected void setup() {}
@Override
protected void loop() {}
public static void main(String[] args) {
try {
String serialPort = "/dev/tty.usbmodem1421";
ArduinoTestWrite arduino = new ArduinoTestWrite(serialPort);
arduino.runArduinoProcess();
Thread.sleep(2000);
if (outPin instanceof PWMPin)
arduino.analogWrite((PWMPin)outPin,onVal);
else if (outPin instanceof DigitalPin) {
arduino.pinMode((DigitalPin)outPin, PinMode.OUTPUT);
arduino.digitalWrite((DigitalPin)outPin,onVal);
}
System.out.println("Turning on LED with byte value: " + onVal);
Thread.sleep(1000);
arduino.stopArduinoProcess();
} catch (Exception e) { e.printStackTrace(); }
}
}
creating a DigitalWriteMsg(DigitalPin pin, DigitalState value) with
is not turning on 5V - powering an led makes it only blink very dimly
in contrast using writing analog to PWM with
makes it light up like a daemon. actually powering the PWMPin with (byte)1 gives the same brightness as DigitalState.HIGH.
i am thinking that writing DigitalState.HIGH to the DigitalPin ought to send (byte)127. several ways I can think of doing this ...
any prefs? obvious fix until then ... use PMWpins and output the (byte)127 to analogWrtite if you want the whole level of voltage on the pin