minimize cable to extruder


i would like to build a PCB with stepperdriver for the extruder( only if possible )  , power mosfet for the heater analog input for the thermistor and n° 2 digital low power output for the vent's . 
this i would like to control in from fimware by i2C or somthing else . 
is it possible that the firmware supports the "remote board" .

Comments

  • Not for the stepper driver. We need to set steps very quickly in an interrupt, I2C is much too slow and also I2C/SPI are not allowed in interrupts in firmware, only in main thread.

    For fan/heater it is not supported but doable if you can program. Just modify the function setting fan, heater or getting temperture to send values instead of doing analog read, changing pwm ... SO if you can program that would be no problem. But you need step/dir/enable signal for stepper in addition.
  • Thanks i will try . 

  • Thanks i will try . 

  • hi everybody . 
    i  make two sketches , one for the master( to be integrated to the repetierfirmware  and the second the slave for the arduino on the pcb for extruder . 
    in this way i need at the extruder PCB only the 12Vdc , 5V and GND + two wires for the I2C. likeyou told me i need also the step and direction signal for the stepper driver wich is mounted to the PCB. 
    so i can read the value of two hotend teperature, control 2x mosfet for heater, control 2x fan for hotend+ 2x fan for colling+ steper enable. on only 5 wires + stepper pule and direction. 
    my problem now is that i'm not sure in wich way i ca integrate (and how) the master sketch to the repetierfirmware . 
    I am grateful for every idea
    thomas 

    NB i surely in the end i've to clenup the sketch from junk needed for controll

    master sketch ------------------------------------------------------------------------------------------------------------------------------

    /* I2C communication between arduino (repetier-firmware and remote Arduino 
     *  master unit
     *  the master will richiest 2 bytes from slave unit ( temperatur of TH1 and TH2 )
     *  the master will send the state of 1 byte to the slave unit for fan and heater controll . 
     *  
     * read the values of two extruder temperatur   firstbyte+secondbyte
     * data 
     * control a mosfet for two heaters             bit 0+1
     * controll two hotend fan's                     bit 2+3
     * control two fan's for print cooling.         bit 4+5 
     *  stepper enable + reserve                    bit 6+7                                    bit 6+7
     * pooling time 100ms
     created by thomas greif 12/11/2019
     note: the sketch has to be cleard up from controlfunctions 
    */
    #include <Wire.h>

    //  set pin numbers:
    const int buttonPin12 = 12;     // the number of the pushbutton pin
    const int buttonPin11 = 11; 
    const int buttonPin10 = 10; 
    const int buttonPin9 = 9; 

    const int ledPin6 =  7;      // the number of the LED pin
    const int ledPin5 =  6;
    const int ledPin4 =  5;
    const int ledPin3 =  4;

    // variables will change:
    int buttonState1 = 0;         // variable for reading the pushbutton status
    int buttonState2 = 0;  
    int buttonState3 = 0; 
    int buttonState4 = 0;

    byte Data = 0;              // data to send  to slave 


    void setup() {
    Serial.begin(9600);         // inizialize  serial only for control

    Wire.begin();               // inizialize  wire


            // initialize the LED pin as an output:
                pinMode(ledPin6, OUTPUT);  pinMode(ledPin5, OUTPUT);  pinMode(ledPin4, OUTPUT);  pinMode(ledPin3, OUTPUT);
            // initialize the pushbutton pin as an input:
                pinMode(buttonPin12, INPUT);pinMode(buttonPin11, INPUT);pinMode(buttonPin10, INPUT);pinMode(buttonPin9, INPUT);
                  }
    // main loop

    void loop() {

    Wire.requestFrom(7,2);        // riechiest from slave(7)  two bytes :
      while(Wire.available()){
          byte firstbyte  = Wire.read();  // first Byte 
          byte secondbyte  = Wire.read();   // second Byte
    // print only for control   
      Serial.print(firstbyte);
      Serial.print("+");  
      Serial.print(secondbyte);
      Serial.print(" as Bin "); 
      Serial.print(Data, BIN);
    }
    Serial.println();             // next line

      
    // read the state of the pushbutton value   only for simulation 
      buttonState1 = digitalRead(buttonPin12);
      buttonState2 = digitalRead(buttonPin11);
      buttonState3 = digitalRead(buttonPin10);
      buttonState4 = digitalRead(buttonPin9);
      

      // check if the pushbutton if pressed  the buttonState is HIGH:
      // to be changed by the bit of repetier-firmware 
     
      if (buttonState1 == HIGH) {
        // turn LED on:
        digitalWrite(ledPin6, HIGH);
        bitWrite(Data, 0, 1);
      } else {
        // turn LED off:
        digitalWrite(ledPin6, LOW);
        bitWrite(Data, 0, 0);  
      }
    if (buttonState2 == HIGH) {
        // turn LED on:
        digitalWrite(ledPin5, HIGH);
        bitWrite(Data, 1, 1);
      } else {
        // turn LED off:
        digitalWrite(ledPin5, LOW);
         bitWrite(Data, 1, 0);   
      }
    if (buttonState3 == HIGH) {
        // turn LED on:
        digitalWrite(ledPin4, HIGH);
        bitWrite(Data, 2, 1);
      } else {
        // turn LED off:
        digitalWrite(ledPin4, LOW);
         bitWrite(Data, 2, 0);   
      }
      if (buttonState4 == HIGH) {
        // turn LED on:
        digitalWrite(ledPin3, HIGH);
        bitWrite(Data, 3, 1);
      } else {
        // turn LED off:
        digitalWrite(ledPin3, LOW); 
         bitWrite(Data, 3, 0);  
      }
       bitWrite(Data, 4, 0);
        bitWrite(Data, 5, 0);
         bitWrite(Data, 6, 0);
          bitWrite(Data, 7, 0);
    // ende byte bitweise schreiben       

    Wire.beginTransmission(7);
    Wire.write(Data);             // prima byte da trasmettere al slave 
    Wire.endTransmission();

    delay(100);
    }

    slave sketch ---------------------------------------------------------------------------------------------------------------------------------

    /* I2C communication between arduino (repetier-firmware and remote Arduino 
     *  Slave unit
     *  the master will richiest 2 bytes from slave unit ( temperatur of TH1 and TH2 )
     *  the master will send the state of 1 byte to the slave unit for fan and heater controll . 
     *  
     * read the values of two extruder temperatur   firstbyte+secondbyte
     * data 
     * control a mosfet for two heaters             bit 0+1
     * controll two hotend fan's                     bit 2+3
     * control two fan's for print cooling.         bit 4+5 
     *  stepper enable + reserve                    bit 6+7  
     * pooling time 100ms
     created by thomas greif 12/11/2019
     note: the sketch has to be cleard up from controlfunctions 
    */


    #include <Wire.h>



    // impostazione 
    const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to
    const int analogInPin1 = A3;  // Analog input pin that the potentiometer is attached to
    const int analogOutPin = 11; // Analog output pin that the LED is attached to

    int sensorValue = 0;        // value read from the pot
    int sensorValue1 = 0;        // value read from the pot

    int outputValue = 0;         // value output to the PWM (analog out)
    int outputValue1 = 0;        // value output to the PWM (analog out)


    byte Data = 0;                 // recive data primo byte


    // inizio setup 
    void setup() {
    pinMode(10, OUTPUT);          // set pin 10 as output
    pinMode(9, OUTPUT);           // set pin 9 as output
    pinMode(8, OUTPUT);           // set pin 8 as output
    pinMode(7, OUTPUT);           // set pin 7 as output
    pinMode(6, OUTPUT);           // set pin 6 as output
    pinMode(5, OUTPUT);           // set pin 5 as output
    pinMode(4, OUTPUT);           // set pin 4 as output
    pinMode(3, OUTPUT);           // set pin 3 as output

      
      //pinMode(pulsantePin, INPUT);  // set pulsantePin as input
      
      Wire.begin(7);                // start wire
      Wire.onRequest(answer);     // initialize answer
      Wire.onReceive(recive);       // initialize recive
      
      
      Serial.begin(9600);             // initialize serial communications at 9600 bps:
    }

    // end setup 


    // inizio ciclo

    void loop() {

    // read analog value and output at A0 on a 255 base
      sensorValue = analogRead(analogInPin);                // read the analog in value:  
      outputValue = map(sensorValue, 0, 1023, 0, 255);      // map it to the range of the analog out:  
      analogWrite(analogOutPin, outputValue);               // change the analog out value:

    // read analog value and output at A0 on a 255 base
      sensorValue1 = 300;                // read the analog in value:  
      outputValue1 = map(sensorValue1, 0, 1023, 0, 255);      // map it to the range of the analog out:  
     // analogWrite(analogOutPin, outputValue);               // change the analog out value:

      
           
    // wait 10 milliseconds before the next loop 

      delay(10);
    }


    // aswer for the master
      void answer(){
        
      Wire.write(outputValue);
      Wire.write(outputValue1);
    }
    // end of answer 


    // recived data from master 
      void recive(){
        
      Data=0;                               //set data to 0  in binario 00000000
     while(Wire.available()){
      Data = (Wire.read());
     // print data as binary
        Serial.println(Data, BIN);

    // end print 



    // loop for output's 
    int i=0;
    for (i = 0; i < 8; i++) {
     if (bitRead(Data, i) == 1) {
     digitalWrite(10-i, HIGH);               // if  1 == out i on
     //Serial.println("hight");
      } else {
        // turn LED off:
        digitalWrite(10-i, LOW);          // if  0 == out i off 
        //Serial.println("low"); 
              }
                            }  
     }

    }
  • The temperature control is all I see and all needed as step/dir/enable is using direct pins I guess. Looks like you only want pwm value from firmware and get sensor read.

    All is in Extruder.cpp. Only thing is your loop is bad on slave side. You will never get a do all command. For each action you need an own command and after getting the command read the payload or reserve some bits as payload. E.g. lets say bits 0-3 are commands so you can have 16 actions and you can add in bits 4-7 also 4 bit payload e.g. enable or disable a light/enable/.. For setting PWM you need a extra byte with value of course but you can encode in bit which of the 2 heaters is meant.

    That you need to find all the places where normally pins/pwm is set or analog value gets read and add some code like in your master part to execute exactly that action. That is why you need individual actions and can not make a all in one solution.
Sign In or Register to comment.