GPIO Pins on DUEX5 Useage
-
You can't read a PWM value on a GPIO pin except by timing the high and low transitions and doing some calculations from those times; or by smoothing the PWM signal (e.g. using a RC filter) and feeding the resulting voltage onto an analog input. You would need to modify the firmware to do that.
If you control the PWM value, why do you need to read it anyway?
-
What I have is GPIO1 of the Duex5 connected to Analog PIN "A2" of an Arduino Pro Mini. In Config.g, I have this to enable the GPIO pin: M950 P0 C"duex.gp1"
I have it all working and can change the addressable LED Lighting colors using the G Codes shown in the sketch code. I use the M42 command such as M42 P0 S20 which changes the LEDS to white. I've added Gcodes to some of the system files that run and the lights change depending on what the printer is doing.
Since I'm not a programmer, I'm not exactly sure what the code is doing when it references: if (Value_pwm> 200 && Value_pwm <250) but just guessing, its reading the PWM value that changes when sending the M42 command.
I was wondering how high I can go with the if (Value_pwm> xxx && Value_pwm <xxx) before exceeding the limits of the Duet System. As my earlier message said, I tried: if (Value_pwm> 625 && Value_pwm <675) without success. Either I goofed the code or sending the M42 P0 S79 didn't do anything. I also tried S73,4,5,6,7,8, and a few after that without success.
-
This post is deleted! -
@Danal, Yes, it's a 5v pro mini and it's a one way direction from DUEX5 GPIO1 to Pin A2 Of the Pro Mini. I do have a 3.3 to 5v logic level converter device, I should put it in between? If I got a 3.3 v Pro Mini, I'd have more room to add PWM values?
Bottom line, I'm fairly new to Arduino and am trying to learn code. If you look at the first post of the code I've commented what each GCode does, I copied it in again below and bolded the GCodes and Colors. After I got it all working I thought I would try adding another color Purple. That code is bolded in the first post.What you are saying indicates that my guess of 625-675 is above the range. If you study the code I was trying to add (again just copying, pasting and altering the PWM in the same way the other codes are) It won't work. But, if I lower the PWM to say 600-620 or so It might work? If I tighten the ranges of the other colors I could also add more, keeping the last one under 624? I suppose if it's too tight, the arduino may not see the change? I studied the G42 write up but it wasn't clear enough for me. Thank you so much for replying, what you have said has helped me understand this even more.
if (Value_pwm> -1 && Value_pwm <100) {Serial.println (Value_pwm); Serial.println ("Sleep"); Standby ();} // M42 P0 S09 in Duet
if (Value_pwm> 125 && Value_pwm <175) {Serial.println (Value_pwm); Serial.println ("White"); White ();} // M42 P0 S20 in the Duet
if (Value_pwm> 200 && Value_pwm <250) {Serial.println (Value_pwm); Serial.println ("Red"); Red ();} // M42 P0 S29 in the Duet
if (Value_pwm> 275 && Value_pwm <325) {Serial.println (Value_pwm); Serial.println ("Green"); Green ();} // M42 P0 S39 in the Duet
if (Value_pwm> 350 && Value_pwm <400) {Serial.println (Value_pwm); Serial.println ("Blue"); Blue ();} // M42 P0 S49 in the Duet
if (Value_pwm> 425 && Value_pwm <475) {Serial.println (Value_pwm); Serial.println ("Off"); Off ();} // M42 P0 S58 in the Duet
if (Value_pwm> 525 && Value_pwm <575) {Serial.println (Value_pwm); Serial.println ("On"); On ();} // M42 P0 S68 in the Duet -
This post is deleted! -
@wkellyo said in GPIO Pins on DUEX5 Useage:
// Read the value of PWM_PIN and set it to Value_pwm
Value_pwm = pulseIn (PWM_PIN, HIGH);WAIT!!! I just noticed that the Arduino sketch is using PulseIn to read A0. I thought it was using analogRead()... it is not.
Therefore ALL of my comments about voltages and ranges GO AWAY. There will be no difference between a 5V and 3.3V Pro Mini. The range will not be 1024*(3.3/5), etc, etc. I've actually deleted a couple of posts above, to avoid confusion:
The following things are still true:
- When using a 5V pro mini, NEVER connect one of its outputs to the Duet; that will harm the Duet. Going the other way, Duet output to Arduino input, is OK-ish with a lot of caveats.
- A level converter will not really help anything in this situation. 3.3V logic output generally switches 5V input cleanly.
And:
- Do set up the serial monitor in Arduino, at 115200
- Do use the Duet web console to enter a series of M42 P0 Snn commands, with incrementing S values.
Use the information you learn from this to decide what M42 commands relate to what numbers on the Arduino, and therefore what ranges you wish to use.
-
@Danal Again, thanks for taking the time to help me. I've read about using the serial monitor, guess it's time to dig in and learn how to use it. I will be changing the Arduino Pin to A3 soon so I can use a 4 Pin shell housing to go from GND, VCC, skip, A3 with one plug. If you would like to see the printer in action Homing watch for the bed leds being in the Sleep mode then going full green while it's homing. After homing, they turn back to sleep. As soon as I get this ironed out, I'll be adding the GCodes to the files as we discussed in macro post. In the video you can see the light change for every direction due to having a "homeall.g file with nothing but pointers to the other homing files. I've rewritten the homeall.g with it's own code so the lights are on during the entire operation. Just looks cleaner to me.
-
For anyone following this I got the Purple color to work perfectly and was sooo close
if (Value_pwm> 625 && Value_pwm <675) {Serial.println (Value_pwm); Serial.println ("Purple"); Purple ();} // M42 P0 S81 in the Duet
This code worked! I originally had an S79 but after taking @Danal advice I got the serial monitor working and studied it and found the PWM value was just a bit short of working. S81 in the code did the trick!
-
Wooo Hooo!
-
@wkellyo how it's look your config.g for this application with arduino?