Filament diameter sensor
-
So recently i saw this video of Thomas Sanladerer (https://www.youtube.com/watch?v=RYgdLPe_T0c) and since i'm working with really unreliable experimental ceramic filament i wanted to implement this on my toolchanger.
Assambly was not a problem and since i have 4 inputs i wanted to feed the arduino with the individual data and just send the gcode (M221 Sx Dx) to the duet.
And here i m getting out of my comfort zone because my coding skills resamble that of a braindead monkey.
[code]
// select the input pin for the potentiometer
int sensorPin0 = A0;
// select the input pin for the potentiometer
int sensorPin1 = A1;
// select the input pin for the potentiometer
int sensorPin2 = A2;
// select the input pin for the potentiometer
int sensorPin3 = A3;// select the pin for the LED
int ledPin = 13;// variable to store the value coming from the sensor
int sensorValue0 = 0;
// variable to store the value coming from the sensor
int sensorValue1 = 0;
// variable to store the value coming from the sensor
int sensorValue2 = 0;
// variable to store the value coming from the sensor
int sensorValue3 = 0;int gcode0 = 0;
int gcode1 = 0;
int gcode2 = 0;
int gcode3 = 0;#include "GCodeSerial.h"
GCodeSerial output(Serial.ATmega328P);
void setup()
{
pinMode(ledPin,OUTPUT); Serial.begin(57600);
}
void loop(){sensorValue0 =
analogRead(sensorPin0);
gcode0 = ((sensorValue0-516)*0.73913043478)+62;sensorValue1 =
analogRead(sensorPin1);
gcode1 = ((sensorValue1-516)*0.73913043478)+62;sensorValue2 =
analogRead(sensorPin2);
gcode2 = ((sensorValue2-516)*0.73913043478)+62;sensorValue3 =
analogRead(sensorPin3);
gcode3 = ((sensorValue3-516)*0.73913043478)+62;//T0
if (gcode0 < 95) {delay(1000);Serial.println("");}
else{
if (gcode0 > 120) {delay(1000);Serial.println("NO FILAMENT");}
else{
digitalWrite(ledPin, HIGH);
delay(1000); digitalWrite(ledPin, LOW); delay(1000);
output.write("M221 S");output.write(gcode0);output.write(" D");output.write(A0-14);
}}
//T1
if (gcode1 < 95) {delay(1000);Serial.println("");}
else{
if (gcode1 > 120) {delay(1000);Serial.println("NO FILAMENT");}
else{
digitalWrite(ledPin, HIGH);
delay(1000); digitalWrite(ledPin, LOW); delay(1000);
Serial.write("M221 S");Serial.write(gcode1);Serial.write(" D");Serial.write(A1-14);
}}
//T2
if (gcode2 < 95) {delay(1000);Serial.println("");}
else{
if (gcode2 > 120) {delay(1000);Serial.println("NO FILAMENT");}
else{
digitalWrite(ledPin, HIGH);
delay(1000); digitalWrite(ledPin, LOW); delay(1000);
Serial.print("M221 S");Serial.print(gcode2, DEC);Serial.print(" D");Serial.println(A2-14);
}}
//T3
if (gcode3 < 95) {delay(1000);Serial.println("");}
else{
if (gcode3 > 120) {delay(1000);Serial.println("NO FILAMENT");}
else{
digitalWrite(ledPin, HIGH);
delay(1000); digitalWrite(ledPin, LOW); delay(1000);
Serial.print("M221 S");Serial.print(gcode3, DEC);Serial.print(" D");Serial.println(A3-14);
}}
}
[/code]it looks stupid but it works ... i think at least ... on my serialmonitor i recive for each filament the acording M221 command. There are still placeholders for too little filament or to big filament. But now for sending it to the duet ...
I have no idea how ... well i know i can use the paneldue port using a levelshifter as shown in the cnc style pendant discussion ... but i dont know how
i dont intend on using a panel due so it should be easy (very very oh so very easy) acording to
@danal said in CNC style Pendant:
@janvdg said in CNC style Pendant:
I was wondering if it is possible to send Gcode commands to the duet from a arduino board.
Yes, very easy. Very, very, very easy. Did I mention that it is fairly straightforward? Probably not hard? Have I beat this dead horse enough?
The port on the Duet that is intended to connect to a PanelDUE is a 3.3V TTL level serial port. The serial port on a standard Arduino is a 5 volt TTL level serial, so you'd need a level translator (couple of bucks from Sparkfun)... or, there are 3.3V microcontrollers, such as the ESP32 or ESP8266, both of which can be programmed from the Arduino environment. Very easy.
As I said in the post above, given one or two assumptions about "being in parallel with" a PanelDUE (or just not having a PanelDUE at all), this is extremely simple.
The key is, I'm not really interested in having a pendant, so I need to know that some number of people ARE interested... and if those people will post here in this thread, and/or contact me at "danal (dot) estes (at) gmail (dot) com", we can discuss how to prototype and pursue this.
here is a picture of the hardware not sure if that chaos helps anybody.
I would be really glad about help or input.
-
If I get you right, you want to update the momentary diameter while printing?
That's not just a serial-connection problem, but also needs to be synchronized with the print speed. You'd also need a filament-movement sensor. Also the controller would have to know the distance from your filament sensor and the nozzle to time the extrusionrate based on the diameter you've measured nn.nn millimeters before.
Your current data stream only sends data every nn.nn seconds which is much harder to synchronize. (varying print speed, retractions a.s.o.)[code] // select the input pin for the potentiometer int sensorPin0 = A0; // select the input pin for the potentiometer int sensorPin1 = A1; // select the input pin for the potentiometer int sensorPin2 = A2; // select the input pin for the potentiometer int sensorPin3 = A3; // select the pin for the LED int ledPin = 13; // variable to store the value coming from the sensor int sensorValue0 = 0; // variable to store the value coming from the sensor int sensorValue1 = 0; // variable to store the value coming from the sensor int sensorValue2 = 0; // variable to store the value coming from the sensor int sensorValue3 = 0; int gcode0 = 0; int gcode1 = 0; int gcode2 = 0; int gcode3 = 0; #include "GCodeSerial.h" GCodeSerial output(Serial.ATmega328P); void setup() { pinMode(ledPin,OUTPUT); Serial.begin(57600); } void loop(){ sensorValue0 = analogRead(sensorPin0); gcode0 = ((sensorValue0-516)*0.73913043478)+62; sensorValue1 = analogRead(sensorPin1); gcode1 = ((sensorValue1-516)*0.73913043478)+62; sensorValue2 = analogRead(sensorPin2); gcode2 = ((sensorValue2-516)*0.73913043478)+62; sensorValue3 = analogRead(sensorPin3); gcode3 = ((sensorValue3-516)*0.73913043478)+62; //T0 if (gcode0 < 95) {delay(1000);Serial.println("");} else{ if (gcode0 > 120) {delay(1000);Serial.println("NO FILAMENT");} else{ digitalWrite(ledPin, HIGH); delay(1000); digitalWrite(ledPin, LOW); delay(1000); output.write("M221 S");output.write(gcode0);output.write(" D");output.write(A0-14); }} //T1 if (gcode1 < 95) {delay(1000);Serial.println("");} else{ if (gcode1 > 120) {delay(1000);Serial.println("NO FILAMENT");} else{ digitalWrite(ledPin, HIGH); delay(1000); digitalWrite(ledPin, LOW); delay(1000); Serial.write("M221 S");Serial.write(gcode1);Serial.write(" D");Serial.write(A1-14); }} //T2 if (gcode2 < 95) {delay(1000);Serial.println("");} else{ if (gcode2 > 120) {delay(1000);Serial.println("NO FILAMENT");} else{ digitalWrite(ledPin, HIGH); delay(1000); digitalWrite(ledPin, LOW); delay(1000); Serial.print("M221 S");Serial.print(gcode2, DEC);Serial.print(" D");Serial.println(A2-14); }} //T3 if (gcode3 < 95) {delay(1000);Serial.println("");} else{ if (gcode3 > 120) {delay(1000);Serial.println("NO FILAMENT");} else{ digitalWrite(ledPin, HIGH); delay(1000); digitalWrite(ledPin, LOW); delay(1000); Serial.print("M221 S");Serial.print(gcode3, DEC);Serial.print(" D");Serial.println(A3-14); }} } [/code]
-
@o_lampe
Yes you are definetly right in the bestcase scenario i would delay the input until the moment of extrusion. but since my filament isn' t abruptly changing i'd be happy if it would work dumb like that. Of course your way would be much more sufisticated but i m quite happy getting this working for now. -
@erfreuterstudent
in that case, it would be easiest to NOT send data permanently, but let the Arduino 'listen' to a request-signal coming from the Duet FW. (daemon.g could poll the data every 10seconds)
All you need is a serial data port like on the paneldue header. You don't need a paneldue.
TX to RX and vice versa, same BAUD rate on both sides and you are ready to go. -
@o_lampe
thank you for the help. Yes you are right that would definetly be more elegant especially because i wouldn t need to send info about all the unused extruder. i thought just sending would be easier and to be honest from my setup i have no idea how to change my firmeware besides config.g and a handfull of other .g files that are present in the duet webinterface. if you could point me in the right direction i d be quite happy to learn though. -
@erfreuterstudent
that's a premier for me too, but we'll try.
With a toolchanger you could poll the diameter of the current tool in tpost#.g by using M118 S2 P"toolnumber"
Now the arduino reads this message and sends the aquired data, but here it get's shady for me. It is easy to receive messages and display them on DWC, but reading data into a global variable is unknown to me. I tried it over I2Cport, but fell into the same dark hole...
Maybe @dc42 has a solution now?