boomsya / PET-filament-maker

Scheme, firmware, example of machine which make a filament for a 3d-printer from plastic bottles sripes
The Unlicense
4 stars 0 forks source link

Errors Compiling #1

Open Gokuh1980 opened 8 months ago

Gokuh1980 commented 8 months ago

Hi! did you compile the code without errors? because i´ve installed all the libraries and hace errors with the filter,

`//#define MACHINE2 //melting 2

include

//screen settings

include

include

LiquidCrystal_I2C lcd(0x27, 16, 2); //sometimes the address is 0x3f /* i2c LCD Module ==> Arduino

//configuring I/O pins const int PWM_heat_pin = 3; //for PWM signal to MOSFET (the BJT npn with pullup) const int fan_pin = 6; //fan control const int enable_disable_motor_button_pin = 7; //motor on-off button const int clk_pin = 8; //clk pin from encoder const int data_pin = 9; //pin data from encoder const int dir_button_pin = 10; //pin of the motor rotation direction switch const int rotary_button_pin = 11; //pin of the encoder button const int microstep_pin = 12; //activation 1/16 step const int LED_pin = 13; //LED indication of motor activation const int filament_end_pin = A2; //tape presence sensor const int EN_pin = 2; //on A4988 const int DIR_pin = 4; //on A4988 const int STEP_pin = 5; //on A4988

//setting up the thermistor

include //install ThermistorLibrary by Miguel Califa

// Thermistor object THERMISTOR therm1(A0, // Analog pin 10000, // Nominal resistance at 25 ºC 3950, //thermistor's beta coefficient 10000); // Value of the series resistor //setting up the stepper motor

include //install AccelStepper by Mike McCauley

AccelStepper stepper1(1, STEP_pin, DIR_pin); // (Type of driver: with 2 pins, STEP, DIR)

//variable temperatures

include "GyverPID.h" //install lib ByverPID by AlexGyver

GyverPID regulator(1, 256, 1.4, 10);

include "GyverFilters.h" //install the GyverFilters library by AlexGyver

GMedian<10, int> filtered_temperature; //filter int set_temperature = 222; //Temperature value for washing. Fill in the 0 and use it using the rotary encoder float temperature_read = 0;//current read temperature float last_temperature_read = -100;//prev. reading temperature int last_set_temperature = 0; bool temperature_riched = false; //has the temperature reached the permissible value bool last_temperature_riched = true; //prev. status whether the temperature has reached the permissible value

unsigned long Time, last_LCDdrawTime = 0; byte rotary_button_pressed = 0;//button pressed byte active_menu = 0;//menu activated bool menu_changed = true;//sign that the menu has changed in order to draw it

//change the finished stitches int filament_ended = 1;//sign that the tape has ended: 1 = no tape, 0 = tape available int last_filament_ended = 0;//prev. tape end status unsigned long filament_ended_time = 0;

//Functions for assigning a rotary encoder int clk_State; int dt_State; static uint8_t prevNextCode = 0; static uint16_t store = 0;

//changes for rock motor byte motor_direction;//direction of motor rotation 1 = winding, 0 = winding byte last_motor_direction;//prev. motor rotation direction

define max_speed 1000.0 //maximum speed

const float speeds_percent_arr[7] = {0.0, 6.0, 8.0, 10.0, 16.0, 24.0, 48.0};

Bounce2::Button start_stop_button = Bounce2::Button(); bool stepper_motor_activated = false;//motor activated bool last_stepper_motor_activated = false;//prev. status whether the motor is activated float rotating_speed = 0; // rotating speed float last_rotating_speed = 0;//prev. rotational speed byte current_speed_idx = 3;//current default rotation speed

//count count. drawn rod long cm = 0; long last_cm = -1;

ifndef MACHINE2

define steps_in_cm 1357

endif

ifdef MACHINE2

define steps_in_cm 629

endif

void setup() { pinMode(EN_pin, OUTPUT); // control pin on-off motor digitalWrite(EN_pin, HIGH);//disable the motor by default pinMode(fan_pin, OUTPUT); digitalWrite(fan_pin, LOW);//disable the fan by default stepper1.setMaxSpeed(max_speed);//set the maximum motor speed //pinMode(enable_disable_motor_button_pin, INPUT_PULLUP); //motor on-off button start_stop_button.attach(enable_disable_motor_button_pin, INPUT_PULLUP); start_stop_button.interval(50); start_stop_button.setPressedState(LOW);

pinMode(microstep_pin, OUTPUT); digitalWrite(microstep_pin, LOW);//full step

pinMode(LED_pin, OUTPUT);//indication of motor activation digitalWrite(LED_pin, LOW);

pinMode(PWM_heat_pin, OUTPUT); analogWrite(PWM_heat_pin, 0);

pinMode(dir_button_pin, INPUT_PULLUP);//motor rotation direction switch motor_direction = digitalRead(dir_button_pin); last_motor_direction = 1 - motor_direction;

pinMode(rotary_button_pin, INPUT_PULLUP);//encoder button pinMode(data_pin, INPUT);//encoder pin data pinMode(clk_pin, INPUT);//clk encoder pin

pinMode(filament_end_pin, INPUT_PULLUP);//tape presence sensor filament_ended = digitalRead(filament_end_pin); last_filament_ended = 1 - filament_ended;

TCCR2B = TCCR2B & B11111000 | 0x03;//pin D3 and D11 PWM frequency 928.5 Hz

clk_State = (PINB & B00000001); //remember the initial state of the rotary encoder dt_State = (PINB & B00000010); //remember the initial state of the rotary encoder

PCICR |= (1 << PCIE0); //enable PCMSK0 scan PCMSK0 |= (1 << PCINT0); //set an interrupt on pin D8 when the value changes PCMSK0 |= (1 << PCINT1); //set an interrupt on pin D9 when the value changes PCMSK0 |= (1 << PCINT2); //set an interrupt on pin D10 when the value changes PCMSK0 |= (1 << PCINT3); //set an interrupt on pin D11 when the value changes

lcd.init(); lcd.backlight();

regulator.setDirection(NORMAL); regulator.setLimits(0, 255); regulator.setpoint = set_temperature; }

void loop() { //Temperature values are readable immediately temperature_read = filtered_temperature.filtered(therm1.analog2temp()); //read the temperature

//is there a tape filament_ended = digitalRead(filament_end_pin);

Time = millis(); //working hour

start_stop_button.update();

if (start_stop_button.pressed()) {//the button is pressed stepper_motor_activated = !stepper_motor_activated; if (stepper_motor_activated) { //motor just turned on if ((filament_ended == 1) && (motor_direction == 1)) { stepper_motor_activated = 0; //if there is no rod, we don’t start } if ((stepper_motor_activated == true) && (last_stepper_motor_activated == false)){ //motor just turned on stepper1.setCurrentPosition(0); cm = 0; last_cm = -1; last_stepper_motor_activated = true; } } else { // just turned on the engine last_stepper_motor_activated = false; } }

//delay the end of the tape if (stepper_motor_activated && (motor_direction == 1)) { if (filament_ended == 1) { //just ended = detect when exactly if (filament_ended_time == 0) { filament_ended_time = Time; } } else { filament_ended_time = 0; }

 if ((filament_ended_time == 0) || (Time - filament_ended_time < 44000)) {
   filament_ended = 0; //we say that until the tape ends within 40 seconds after its actual end, so that the tail melts more
 }

}

//insert a PWM signal for heating the mosfet on pin D3 if (motor_direction == 1) { // winding if ((filament_ended == 0) && (temperature_read < 255)) { //winding + there is tape + no overheating regulator.input = temperature_read; analogWrite(PWM_heat_pin, regulator.getResultTimer()); rotating_speed = max_speed * speeds_percent_arr[current_speed_idx] / 100.0; //preliminarily calculate the motor speed, maximum 60% } else { //no tape, overheating - don't heat it up analogWrite(PWM_heat_pin, 0); rotating_speed = 0; }

 //has the temperature reached the required value (minimum 96% of the required)
 temperature_riched = (temperature_read >= set_temperature * 0.96);

 //winding is on + the motor is on + (the tape is stuck or the temperature has not reached the desired value) = turn on the motor (check whether it needs to be heated or not a little higher)
 if (stepper_motor_activated && ((filament_ended == 1) || (temperature_read < set_temperature * 0.96) || (temperature_read >= 255))){
   stepper_motor_activated = false;
 }

} else { //when we wrap the woman up, we don’t warm her up analogWrite(PWM_heat_pin, 0); temperature_riched = false; }

//Current state if (active_menu == 0) { if (menu_changed) { menu_changed = false; lcd.clear(); lcd.setCursor(0, 0); lcd.print("TMP"); lcd.setCursor(7, 0); lcd.print(" -> "); lcd.setCursor(0, 1); lcd.print("SPD"); lcd.setCursor(14, 1); lcd.print("cm"); }

 if (last_filament_ended != filament_ended) { //force the data to be redrawn if the feed status has changed
   last_LCDdrawTime = 0;
   last_rotating_speed = -1;
   last_motor_direction = 1 - motor_direction;
   last_temperature_read = -100;
 }

 if (Time - last_LCDdrawTime > 1500) {
   if (stepper_motor_activated && (motor_direction == 1)) { //if the motor is spinning and winding
     cm = floor(stepper1.currentPosition()/steps_in_cm); //counter of wound rod
   }

   if (last_temperature_riched != temperature_riched) { //draw a sign whether the temperature value has reached the required value
     lcd.setCursor(8, 0);
     if (temperature_rich) {
       lcd.print("=");
     } else {
       lcd.print("-");
     }
     last_temperature_riched = temperature_riched;
   }

   if (last_filament_ended != filament_ended) {//draw whether the tape has ended
     lcd.setCursor(15, 0);
     if (filament_ended == 1) { //tape ended
       lcd.print('-');
     } else {
       lcd.print('+');
     }
     last_filament_ended = filament_ended;
   }

   if ((last_temperature_read != round(temperature_read)) && (motor_direction == 1)) { //draw the current temperature
     lcd.setCursor(5, 0);
     lcd.print(" ");
     lcd.setCursor(4, 0);
     lcd.print((int) temperature_read);
     last_temperature_read = round(temperature_read);
   }

   if (last_motor_direction != motor_direction) { //draw the temperature to which the melting pot tends
     lcd.setCursor(12, 0);
     lcd.print(" ");
     lcd.setCursor(11, 0);
     if ((motor_direction == 1) && (filament_ended == 0)) { //winding + there is a tape
       lcd.print(set_temperature);
     } else { //when we wrap the woman up, we don’t warm her up
       lcd.print("0 ");
     }
     if (motor_direction == 0){ //if we rewind, draw the temperature at 0 so that the motor does not twitch constantly when the temperature changes
       lcd.setCursor(4, 0);
       lcd.print("0 ");
       cm = 0; //we show right away that we don’t count so much winding
     }
     last_motor_direction = motor_direction;
   }

   if (last_cm != cm) { //counter of wound rod in centimeters
     lcd.setCursor(11, 1);
     lcd.print(" ");
     lcd.setCursor(10, 1);
     lcd.print(cm);
     last_cm = cm;
   }

   if (last_rotating_speed != rotating_speed) {//draw the motor speed
     lcd.setCursor(5, 1);
     lcd.print(" ");
     lcd.setCursor(4, 1);
     lcd.print(speeds_percent_arr[current_speed_idx], 0);
     lcd.print('%');
     last_rotating_speed = rotating_speed;
   }

   last_LCDdrawTime = Time;
 }

} else if (active_menu == 1) { //temperature setting menu if (menu_changed || (set_temperature != last_set_temperature)) { lcd.clear(); lcd.setCursor(0, 0); lcd.print("Set temperature"); lcd.setCursor(0, 1); lcd.print(set_temperature, 0); lcd.print(" "); menu_changed = false; } last_set_temperature = set_temperature; }

if (stepper_motor_activated) {//motor is active digitalWrite(LED_pin, HIGH); //LED lights up digitalWrite(EN_pin, LOW); //activate the motor if (motor_direction == 0) { //wind up digitalWrite(microstep_pin, LOW); //full step rotating_speed = -max_speed/2.25; } else { //winding digitalWrite(microstep_pin, HIGH); //1/16 steps }

 if ((motor_direction == 1) && (filament_ended == 0)) {
   digitalWrite(fan_pin, HIGH); //activate the fan
 } else {
   digitalWrite(fan_pin, LOW); //deactivate the fan
 }

} else { digitalWrite(EN_pin, HIGH); //deactivate the motor digitalWrite(fan_pin, LOW); //deactivate the fan digitalWrite(LED_pin, LOW); //LED vimkneno rotating_speed = 0; }

stepper1.setSpeed(rotating_speed); stepper1.runSpeed(); }

//Interruptions for the rotary encoder button ISR(PCINT0_vect) { static unsigned long last_interrupt_time = 0; static int8_t rot_enc_table[] = {0,1,1,0,1,0,0,1,1,0,0,1,0,1,1,0};

clk_State = (PINB & B00000001); //status clk_pin (D8) dt_State = (PINB & B00000010); //status data_pin (D9)

prevNextCode <<= 2; if (dt_State != 0) { prevNextCode |= 0x02; } if (clk_State != 0) { prevNextCode |= 0x01; } prevNextCode &= 0x0f;

if (rot_enc_table[prevNextCode]) { store <<= 4; store |= prevNextCode; if ((store&0xff)==0x2b) {//counterclockwise if (active_menu == 0) {//main menu - here we adjust the speed if (current_speed_idx > 0) { current_speed_idx--; last_LCDdrawTime = 0; } } else if (active_menu == 1) {//temperature control menu if (set_temperature > 0) { set_temperature -= 1; } regulator.setpoint = set_temperature; } } if ((store&0xff)==0x17) {//clockwise if (active_menu == 0) {//main menu - here we adjust the speed if (current_speed_idx < 6) { current_speed_idx++; last_LCDdrawTime = 0; } } else if (active_menu == 1) {//temperature control menu if (set_temperature <= 244) { set_temperature += 1; } regulator.setpoint = set_temperature; } } }

//the button on the encoder is pressed if ((PINB & B00001000) == 0) { //is the button on the encoder rotary_button_pin (D11) pressed? unsigned long interrupt_time = millis(); if (interrupt_time - last_interrupt_time > 200){ rotary_button_pressed = 1; last_interrupt_time = interrupt_time; } } else if (rotary_button_pressed == 1) { //We go through two menus sequentially with skin pressure of the button active_menu++; if (active_menu > 1) { active_menu = 0; } menu_changed = true; last_LCDdrawTime = 0; last_rotating_speed = -1; last_filament_ended = 1 - filament_ended; last_motor_direction = 1 - motor_direction; last_temperature_riched = !temperature_riched; last_cm = -1; rotary_button_pressed = 0; }

//rotation direction switch if (PINB & B00000100) { motor_direction = 1;//winding } else { motor_direction = 0;//wind up } }`

boomsya commented 8 months ago

yes of course, I have two working machines. can you show me compilation error log? 1

Gokuh1980 commented 8 months ago

here are my compiling errors

C:\Users\pvolpe\AppData\Local\Temp.arduinoIDE-unsaved20231126-30704-aqa40b.z17yr\sketch_dec26a\sketch_dec26a.ino: In function 'void loop()': C:\Users\pvolpe\AppData\Local\Temp.arduinoIDE-unsaved20231126-30704-aqa40b.z17yr\sketch_dec26a\sketch_dec26a.ino:147:60: error: 'class THERMISTOR' has no member named 'analog2temp'; did you mean 'analogPin'? temperature_read = filtered_temperature.filtered(therm1.analog2temp()); //read the temperature ^~~ analogPin C:\Users\pvolpe\AppData\Local\Temp.arduinoIDE-unsaved20231126-30704-aqa40b.z17yr\sketch_dec26a\sketch_dec26a.ino:240:14: error: 'temperature_rich' was not declared in this scope if (temperature_rich) { ^~~~ C:\Users\pvolpe\AppData\Local\Temp.arduinoIDE-unsaved20231126-30704-aqa40b.z17yr\sketch_dec26a\sketch_dec26a.ino:240:14: note: suggested alternative: 'temperature_riched' if (temperature_rich) { ^~~~ temperature_riched

exit status 1

Compilation error: 'class THERMISTOR' has no member named 'analog2temp'; did you mean 'analogPin'?

boomsya commented 8 months ago

here is copy of Thermistor library: ThermistorLibrary.zip

You can try to replace files with my variant (folder C:\Users\<USERNAME>\Documents\Arduino\libraries\ThermistorLibrary)

Gokuh1980 commented 8 months ago

oh! Nice! It compiles OK now!!! THANK YOU VERY MUCH!!!!

i have one question, didn´t read all the code, but, do you close loop on motor speed? because when at a fixed speed if you wind up more than one layer the angular velocity will increase making the filament thinner, what do you think? maybe an encoder after the filament is cooler could help?

boomsya commented 8 months ago

some versions before I maked this algorhytm. Here is 2-3 lines of code. In my case every 6 meters I have real +3% of speedup of winding because every layer of filament is +1.75mm of radius. But new features will goes to 104% of code space :( and I have removed this feature. And second - after first layer filament try to wind in center :) and I have one perfect layer and other length is like mountain (cant find right word of this, sorry). But I have measure thickness of filament - all ok, because I wind on slow speed and I have some reserve for speedup. So it is not problem as you and me think :)

I have use 5 (34 gramm filament) or 6 (43 gramm filament) litres bottles. Is variable from 10 to 15 metres of filament. You need to play with steps_in_cm constant for right calculate of length.

Many peoples in my house leave bottles to me and bottles have the thinkess from 0.1mm to 0.25mm. Very good when is .25 because I have more filament in gramms :)

And last - you need to change stripe width according to bottle plastic thinkess!!! I can make some photos of my bottle cutter and how I regulate width of stripes according to thinkess if you need.

boomsya commented 8 months ago

If you interrested, maybe you want to view my new repository (DIY filament dryer) https://github.com/boomsya/filament-dryer

Gokuh1980 commented 8 months ago

Excelent, i understand your explanation, i´ve just started the construction of this pultruder. Could you explain to me the steps_in_cm constant?

ifndef MACHINE2

define steps_in_cm 1357

endif

ifdef MACHINE2

define steps_in_cm 629

endif

you only use this to show % in advance of the process or does other function?

i would love to see photos of your cutter. i understand the issue with strip witdh vs wide, i´ve seen one calculator online.

some filament pultruders put the cutter right in front of the heater, what do you think of this?

btw nice filament dryer!!!

boomsya commented 8 months ago

I have two filament maker machines. Cogs on drives is different. So winded length of filament is different (I counting motor steps) and if I uncomment #define MACHINE2 then compiler works with #ifdef MACHINE2 source code. In other case compiler works with #ifndef MACHINE2 source code. When I make some changes I have upload new firmware into two Arduinos with different "configs". This affects only to calculating length of maked filament.

I never use calculator because (easy to talk on native language, and some hard on english :) ) you have some diameter of hole in extruder, it is not 1.75mm and can be 1.8mm and calculating will be wrong. Best solution is when you have some thinkess (example is 0.15mm) of bottle and makes (for example) width of stripe 10mm and when you wind filament you can see what stripe fold in O-ring tube (real O) - this is good. But if you make 9mm width - you have almost O-ring tube (for example 270 degrees only), and if you make 12mm width - this stripe stucks in extruder or you need more slow down winding or increase temperature for make stripe more elastic. I am always use 222C. But if I see what the filament is stretched very hard (beetwen babine and extruder) - I slowdown speed or increase temperature to 232-236C. For understanding this - I play on stretched filament like on guitar :) if I hear song :) so I need to make life easier to motor :) On ptohos you will se how I regulate width.

"some filament pultruders put the cutter right in front of the heater, what do you think of this?" - If you mean about cutter so I have seen this but you never can cut bottle automatically without problems. So I make strips and wind to DIY babines (from plastic babines but make only 15mm of width) and this babine put before heater.

boomsya commented 8 months ago

20231226_192452 20231226_192501 20231226_192529 20231226_192538 20231226_192626

boomsya commented 8 months ago

final version of machine: on first photo you can see paper box - this is for saving temperature near heater (I dont want to heat my apartment :) in summer hell) and you can see thin babines with stripe winded on it - very useful

20231022_171937 20231022_171950

Gokuh1980 commented 8 months ago

Ohhh wowwww!!! U left me speechless!!! Thank you so much for your explanations! I'll take every recomendation you made! In a couple of months when the heatblock, heater and thermistor arrives i will show you my results! (They are really expensive in my country... Argentina).

Gokuh1980 commented 8 months ago

Hello, how are you? I was looking at the electronic circuit and I saw the potentiometer for motor speed regulation, which is connected to pin A1, however in the program I don't see it. Isn't it more necessary? If I see in the program that the speed is controlled by the encoder, am I right?

image

boomsya commented 8 months ago

yes, you right. Potentiometer I removed in some version of fimware ago because is make some noise in resistance. I mean potentiometer is not very good quality and resistance changing continiolusly +-100 Ohm. So speed of motor changing too. So I was rewrite code to change speed with encoder (and hole from potentiometer I was hide with Noctua logo metal plate). Think I need to update scheme. Thanks.

boomsya commented 8 months ago

and I forget - as you see - stripe from babine goes under panel (with 4 bolts) and after it he goes to heater. So, inside this panel I have sensor of "end of filament". It is like button (from old DVD), like this: 1877718368_w600_h600_1877718368