Hacking Automatic resin filler for Anycubic M3 for other models

I am using an Anycubic Autofill(for an M3 unit) and a Digispark AAtiny85 to be able use the auto fill on other Anycubic machines(possibly other brands. I have come up with this code, but I have never used or programmed motor speed and using an AAtiny85. I was looking for an app or website the would allow uploading of a sketch and the ability to simulate the operation of the unit to test the sketch, but I couldn't.

I was hoping someone can point me in the direction of a simulator, explain how to best test the sketch as the AAtiny doesn't allow you to use the USB for serial monitoring once components have been added to the board, making it hard.

Otherwise could someone possibly check my sketch to let me know if it will work, please.

#define fullvatswitch_pin 1
#define bottlecapapcityswitch_pin 2
#define motor_pwm_pin 4
#define pot_pin A0 //pin 5
//#define pot_value 0
//#define motor_value 200

void setup() { 
Serial.begin(9600);
//define pins
pinMode(fullvatswitch_pin, INPUT);
pinMode(bottlecapapcityswitch_pin, INPUT);
pinMode(motor_pwm_pin, OUTPUT);
pinMode(pot_pin, INPUT);
}
void loop()
{
int pwm_value , pot_value;
pot_value = analogRead (pot_pin);  
pwm_value = pot_value / 4;
//if bottle is empty do not start pump and recheck bottle level
//checkbottlelevel:
if(bottlecapapcityswitch_pin == false){
return;}

//else if resin bottle has resin check vat resin level
else{
if(bottlecapapcityswitch_pin == true) && (fullvatswitch_pin == false);
}
//if vat resin level is below maximum delay pump start by 1 minute
delay(100000);
//start pump
analogWrite(motor_pwm_pin, map(analogRead(pot_pin),0,1023,0,255));
//Serial.println (motor_pwm_pin value);  
//delay pump off by 10 seconds 
delay(10000);
//restart resin level check cycle
return;  
}

You could develop on a virtual UNO or use tinydebug

The other hardware may be a small challenge, but usually you can stand up something useful in the simukator as proxy for hardware it doesn't have.

HTH

a7

Thanks Alto I will look into those. The hardware is basic, two fluid switch(contacts shorter with 3D resin- one in filler bottle, second in vat), the other a mosfet to switch 5v from board to switch 19V-24V and variable PMW speed control with pot. I don't think any of that hardware should pose a problem.

I have got my circuit and sketch working on Wokwi, it functions correctly. However the hardwire circuit sees the pump/solenoid turn on and off constantly. I can't see the problem.

#define fullvatswitch_pin 1
#define bottlecapapcityswitch_pin 2
#define ps_pin 4
//#define pot_value 0
//#define motor_value 200
void setup() 
{ 
//Serial.begin(9600);
//define pins
pinMode(fullvatswitch_pin, INPUT);
pinMode(bottlecapapcityswitch_pin, INPUT);
pinMode(ps_pin, OUTPUT);
digitalWrite(ps_pin, LOW);
}
void loop()
{
//if bottle is empty do not start pump and recheck bottle level
//checkbottlelevel:
if
(digitalRead(bottlecapapcityswitch_pin) == LOW)
{
digitalWrite(ps_pin, LOW);
//Serial.printIn("resin bottle empty");
}
//else if resin bottle has resin check vat resin level
if
((digitalRead(bottlecapapcityswitch_pin) == HIGH) && (digitalRead(fullvatswitch_pin) == LOW))
{
//if vat resin level is below maximum delay pump start by 1 minute
delay(10000);//10s pump delay 0n
//start pump
digitalWrite(ps_pin, HIGH);
//Serial.printIn("soleniods and pump on");
}
if
((digitalRead(bottlecapapcityswitch_pin) == HIGH) && (digitalRead(fullvatswitch_pin) == HIGH))
{
//Serial.println(pwm_pin value);
//delay pump off by 5 seconds 
delay(5000);
digitalWrite(ps_pin, LOW);
//restart resin level check cycle
 
}
}

Wokwi diagram.json

{
  "version": 1,
  "author": "Kevin Bartolo",
  "editor": "wokwi",
  "parts": [
    { "type": "wokwi-attiny85", "id": "tiny", "top": 0, "left": 0, "attrs": {} },
    {
      "type": "wokwi-led",
      "id": "led1",
      "top": -12.34,
      "left": -291.27,
      "attrs": { "color": "blue" }
    },
    {
      "type": "wokwi-pushbutton",
      "id": "btn1",
      "top": -144.86,
      "left": 97.47,
      "attrs": { "color": "green", "bounce": "0" }
    },
    { "type": "wokwi-vcc", "id": "vcc1", "top": 30.65, "left": -83.94, "attrs": {} },
    { "type": "wokwi-gnd", "id": "gnd1", "top": 93.07, "left": 40.47, "attrs": {} },
    {
      "type": "wokwi-pushbutton",
      "id": "btn2",
      "top": -141.32,
      "left": -103.84,
      "attrs": { "color": "red", "bounce": "0" }
    },
    {
      "type": "wokwi-resistor",
      "id": "r1",
      "top": -83.2,
      "left": -196.33,
      "attrs": { "value": "1000" }
    },
    {
      "type": "wokwi-resistor",
      "id": "r2",
      "top": -87.62,
      "left": 20.17,
      "attrs": { "value": "1000" }
    },
    {
      "type": "wokwi-led",
      "id": "led2",
      "top": -206.73,
      "left": -43.41,
      "attrs": { "color": "red" }
    },
    {
      "type": "wokwi-led",
      "id": "led3",
      "top": -202.31,
      "left": 171.98,
      "attrs": { "color": "green" }
    }
  ],
  "connections": [
    [ "gnd1:GND", "tiny:GND", "black", [ "v0" ] ],
    [ "gnd1:GND", "led1:C", "black", [ "v0.36", "h-219.99" ] ],
    [ "btn1:2.l", "vcc1:VCC", "red", [ "h-29.19", "v95.29", "h-127.02", "v19.88" ] ],
    [ "btn2:1.l", "vcc1:VCC", "red", [ "h-21.17", "v127.32" ] ],
    [ "tiny:PB4", "led1:A", "green", [ "v49.63", "h-179.95" ] ],
    [ "r1:1", "tiny:PB1", "gold", [ "v52.25", "h220.42" ] ],
    [ "r2:1", "tiny:PB2", "violet", [ "v0" ] ],
    [ "r1:1", "btn2:2.l", "gold", [ "v0" ] ],
    [ "r1:2", "gnd1:GND", "black", [ "v12.48", "h223.48", "v149.12" ] ],
    [ "btn1:1.l", "r2:1", "violet", [ "h0" ] ],
    [ "r2:2", "gnd1:GND", "black", [ "v-0.77", "h26.86", "v171.21" ] ],
    [ "tiny:VCC", "vcc1:VCC", "red", [ "v-5.42", "h-39.55" ] ],
    [ "led2:C", "r1:2", "black", [ "v0" ] ],
    [ "led3:C", "r2:2", "black", [ "v0" ] ],
    [ "led2:A", "btn2:2.l", "gold", [ "v77.57", "h-91.14" ] ],
    [ "led3:A", "btn1:1.l", "violet", [ "v9.09", "h-95.56" ] ]
  ],
  "dependencies": {}
}

For a Resin 3D printer auto filler Digispark aatiny85. The circuit tests firstly for resin in the filler bottle. If resin is present, then it checks if the print vat is full. If resin in bottle is true and vat is false, then after 10s it turns on the pump and solenoids via a mosfet, to switch on 24V dc to activate pump and solenoids. If vat is full and resin bottle is full then turn of pump and solenoids of after 5 sec.

Thanks and in advance.

Me neither.

Can you test IRL using LEDs and no other output? No pumps or solenoids or other things, just proxy LEDs with series current-limiting resistors.

How are you powering everything?

Even a hand drawn schematic with how everything is connected with attention to where everything is getting power woukd help.

BTW wokwi has a "share" function, you can get a URL and paste it here when you have something to show. We'll be able to see it and run it and stuff, but not mess with yours.

Put this in the setuo() function to see if you are getting resets you don't notice:

  Serial.begin(9600);
  Serial.println("Reset!");

a7

#define bottlecapapcityswitch_pin 2
if(bottlecapapcityswitch_pin == false)

bottlecapapcityswitch_pin will never be false. It will always be equal to 2.

I think you meant:
if((digitalRead(bottlecapapcityswitch_pin)) == false)

else{
if(bottlecapapcityswitch_pin == true) && (fullvatswitch_pin == false);`

You already know the bottlecapapcityswitch_pin reading is true otherwise the code would not be in this "else"

No need to check resin bottle level here - if the vat is full the pump wants switching off.

The circuit is like on wokwi except running an led via a mosfet(Instead of the pump and solenoids which will connect to a 24v supply) which is connected to pin 4. The board is powered from a 5v supply. For test case the led is powered off the same 5v supply.

thanks

I also tested the mosfet - K3568 manually triggering it with a 5v wire, it works fine, however when 5v trigger is removed, there is a 7sec delay as the LED dims to off. Which I don't understand why this is occurring.

ok thanks

Probably no gate pull down resistor. Impossible for us to know without a schematic

I added to your wokwi the TinyDebug system and I made a few minor changes.

If you could explain what you need to have happen, or how this is supposed to work, that would help. Perhaps you already did. I'm out the door just now, I'll reread the thread later.

It might be simpler to get the algorithm running using a Uno in the simulator.

Would slide switches make more sense or easier testing?

Test it here in the wokwi.

// https://wokwi.com/projects/359457444067954689
// https://forum.arduino.cc/t/hacking-automatic-resin-filler-for-anycubic-m3-for-other-models/1097122

// TinyDebug mini-manual:
//    # include "TinyDebug.h" - Debug.begin(); - Debug.println(F("Hello Tiny!"));

# include <TinyDebug.h>

# define fullvatswitch_pin 1
# define bottlecapapcityswitch_pin 2
# define ps_pin 4

void setup()
{
  Debug.begin();

//define pins
  pinMode(fullvatswitch_pin, INPUT);
  pinMode(bottlecapapcityswitch_pin, INPUT);
  pinMode(ps_pin, OUTPUT);
  digitalWrite(ps_pin, LOW);
}

void loop()
{
  byte bottleCapacity = digitalRead(bottlecapapcityswitch_pin);
  byte vatFull = digitalRead(fullvatswitch_pin);

  delay(250); // just until

  if (!bottleCapacity) {
    digitalWrite(ps_pin, LOW);
    Debug.println(F("resin bottle empty"));
  }

  if (bottleCapacity && !vatFull) {
    Debug.println(F("one minute pump delay 5 seconds"));
    delay(5000);//1 minute pump delay

    digitalWrite(ps_pin, HIGH);
    Debug.println(F("soleniods and pump on"));
  }

  if (bottleCapacity && vatFull) {
    Debug.println(F("delay pump off 3 seconds"));
    delay(3000);
    digitalWrite(ps_pin, LOW);
  }
}

L8R - very warm and humid, light clouds, no wind = beach time. :expressionless:

a7

thanks, i tested in wokwi and it works the same as mine did. i won't get to hard test it next few days flat out with life stuff. i will post results once i do. have a gret weekend and thanks again for your help.

the schematic is what is in the wokwi sketch, with the led on the output in replacement for the mosfet which will act as a switch for the 24v supply which powers the pump and solenoids.
with regards to the pull down resistor resistor which pin does that go on on the mosfet, so I can try it. The circuits I found similar to what I needed as examples to model mine off, were all set up as mine is. FYI The off delay really doesn't affect the operation of the unit, I just wanted to understand why it was happening, purely for my learning.

Thanks for taking the time to assist me. My programming background is in PLC so I am just starting out with Arduino.

I use a 10K from Gate to ground. This is to keep the gate pin from floating when you drive it low. Others may use a different value.

This is the full skinny, give it the three minutes it claims to need!

image

HTH

a7

I'll chuck one in and report back. Thanks

Can someone explain why this sketch comes up with a upload failure, but compiles and works on Wokwi (AnycubicAutofillHackV3test - Wokwi ESP32, STM32, Arduino Simulator) :

Sketch uses 734 bytes (11%) of program storage space. Maximum is 6586 bytes.
Global variables use 6 bytes (1%) of dynamic memory, leaving 506 bytes for local variables. Maximum is 512 bytes.

Please plug in the device (will time out in 60 seconds) ...
Device search timed out!
Failed uploading: uploading error: exit status 1

# define fullvatswitch_pin 1
# define bottlecapapcity_pin 2
# define ps_pin 4

void setup() 
{ //define pins
pinMode(bottlecapapcity_pin, INPUT);  //bottlecapapcityswitch_pin
pinMode(fullvatswitch_pin, INPUT);   //fullvatswitch_pin
pinMode(ps_pin, OUTPUT);   //soleniods and pump on
//digitalWrite(ps_pin, LOW); //set output to low

}
void loop()
{
//digitalWrite(ps_pin, LOW);
byte bottleCapacity = digitalRead(bottlecapapcity_pin);
byte vatFull = digitalRead(fullvatswitch_pin);

  //delay(250); // just until

//if bottle is empty do not start pump and recheck bottle level
//checkbottlelevel and vat level:
if (!bottleCapacity) {
    delay(2500);
    digitalWrite(ps_pin, LOW);
//Serial.printIn("resin bottle empty or vat level full");
}

if (bottleCapacity && !vatFull) {
   // Debug.println(F("one minute pump delay 5 seconds"));
    delay(5000);//1 minute pump delay
    digitalWrite(ps_pin, HIGH);
    delay(5000);//1 minute pump delay
//Serial.printIn("soleniods and pump on");
}

if (vatFull) {
   // Debug.println(F("one minute pump delay 5 seconds"));
    delay(2500);//1 minute pump delay
    digitalWrite(ps_pin, LOW);
    delay(2500);//1 minute pump delay
//Serial.printIn("soleniods and pump on");
}

}

whilst this one does upload, I can't see an issue:

# define fullvatswitch_pin 1
# define bottlecapapcity_pin 2
# define ps_pin 4

void setup() 
{ //define pins
pinMode(bottlecapapcity_pin, INPUT);  //bottlecapapcityswitch_pin
pinMode(fullvatswitch_pin, INPUT);   //fullvatswitch_pin
pinMode(ps_pin, OUTPUT);   //soleniods and pump on
//digitalWrite(ps_pin, LOW); //set output to low

}
void loop()
{
//digitalWrite(ps_pin, LOW);
byte bottleCapacity = digitalRead(bottlecapapcity_pin);
byte vatFull = digitalRead(fullvatswitch_pin);

  delay(250); // just until

//if bottle is empty do not start pump and recheck bottle level
//checkbottlelevel and vat level:
if (!bottleCapacity || vatFull) {
    delay(2500);
    digitalWrite(ps_pin, LOW);
//Serial.printIn("resin bottle empty or vat level full");
}

if (bottleCapacity && !vatFull) {
   // Debug.println(F("one minute pump delay 5 seconds"));
    delay(5000);//1 minute pump delay
    digitalWrite(ps_pin, HIGH);
//Serial.printIn("soleniods and pump on");
}

}