1

Topic: Firmware FilaWinder Study

I begin to study the filawinder firmware.. and i've some question...

at the beginning of main file there is..

//Variables for moving the guide
float guide_min = EEPROM.read(2);           //Right limit for filament guide
float guide_max = EEPROM.read(1);          //Left Limit for Filamnet guide

and some after this float are used by 

**********************************
if (digitalRead(3) == 0 && digitalRead(8) == 1) {     //If guide max nutton is pressed go to calibrate_max
                                                      //calibrate_max will loop while the button is held down.
calibrate_max();                                      //When the button is let up it will return here and write the
EEPROM.write(1, guide_max);                           //new value to the EEPROM
}

if (digitalRead(8) == 0 && digitalRead(3) ==1) {      //If guide min button is pressed go to guide min

calibrate_min();
EEPROM.write(2, guide_min); 
}
*************************************

but i've read on the arduino reference the eeprom write or read..

arduino.cc/en/Reference/EEPROMWrite#.UweIoIW_icE

work with A BYTE... and the float value (from the same reference) is 4 bytes...

arduino.cc/en/Reference/Float#.UweL3IW_icE

so it's possible you write in eeprom only a little piece of this float.. is true?
on the arduino forum i've found this post..

forum.arduino.cc/index.php/topic,41497.0.html

this explain how write float or double value (4 byte value) with a example..

Writing float values to Eeprom

****************************

#include <EEPROM.h>


template <class T> int EEPROM_writeAnything(int ee, const T& value)
{
    const byte* p = (const byte*)(const void*)&value;
    int i;
    for (i = 0; i < sizeof(value); i++)
        EEPROM.write(ee++, *p++);
    return i;
}

template <class T> int EEPROM_readAnything(int ee, T& value)
{
    byte* p = (byte*)(void*)&value;
    int i;
    for (i = 0; i < sizeof(value); i++)
        *p++ = EEPROM.read(ee++);
    return i;
}


double testInt[12] = { -12.5, -10.00, -5.7, 0, 2.45, 2.90, 3.10, 4 , 5.6, 7.9, 5.5, 4};
byte noElem = 12;
unsigned int baseAddr = 0;
unsigned int n = 0;

void setup() {
  Serial.begin(9600);

  // write data to eeprom 
  for (int i=0; i <= noElem-1; i++){
    n = EEPROM_writeAnything( (i*4)+baseAddr, testInt[i]);
  }

  // read data back
  for (int i=0; i <= noElem-1; i++){
    double val;
    int addr = (i*4)+baseAddr;
    n = EEPROM_readAnything( addr, val);
    Serial.println(val);
  }
}

void loop() {
}

*******************************

I'm right or i'm wrong and the eeprom.write can work with 4 byte alone ?

thx

2

Re: Firmware FilaWinder Study

I used float for guide positions so I could use decimals, and not be limited to moving the servo in steps of a full degree.   If that means the left or right limits get rounded up or down when saved to EEPROM, it's not a big deal, the limits don't need to be that precise.

3 (edited by vincenzo.matacelo 2014-02-21 19:55:46)

Re: Firmware FilaWinder Study

It you say that it's meaning the compiler make a conversion from float to int when write it the eeprom, have you seen if the return of the read is the same value only rounded? My warried was the trunking of value from 4 to 1 byte that meaning changing complete of value stored!

4

Re: Firmware FilaWinder Study

I'm not sure what exactly is going on in the EEPROM, but the guide limits as read from EEPROM seem to be in the right place.

One thing I would like to do is have the values created by the sensor calibration saved in EEPROM so it doesn't have to be recalibrated every time you turn the winder on.  It would also mean that if the Arduino restarted for some reason, the sensor could continue to operate so long as the filament was still in front of it.

The calibration and filament tracking all happens inside the QTR library, and at this point I haven't looked into the library closely enough to figure out how to make it take those values from the EEPROM and use them as defaults before configuration.

5 (edited by vincenzo.matacelo 2014-02-22 21:22:11)

Re: Firmware FilaWinder Study

While i'm studing the firmware i'm founding some error... for example also at the beginning of the file you think to set analog pin but really reset the digital pin.. luck either are input.. here

 pinMode(motor_spoolerPin, OUTPUT);
  pinMode(hall_a_Pin, INPUT);
  pinMode(3, INPUT);
  pinMode(8, INPUT);
  pinMode(guidePin, OUTPUT);
  pinMode(sensor_setPin, INPUT);
  pinMode(toggle, INPUT);
  pinMode(sensor_1, INPUT);
  pinMode(sensor_2, INPUT);
  pinMode(sensor_3, INPUT);
  pinMode(sensor_4, INPUT);
  pinMode(13, OUTPUT);
  pinMode(9, INPUT);
  pinMode(10, INPUT);
  pinMode(11, INPUT);
  pinMode(12, INPUT);

but a few row up you write

//Digital Pins
int hall_a_Pin = 7;           // Hall sensor A
int sensor_setPin = 4;           //Button for setting the Pull PID setpoint
int motor_spoolerPin = 5;     //PWM pin for spooler motor
int guidePin = 6;             //Guide servo
int guide_maxPin = 3;        //Button for setting the Max Guide limits
int guide_minPin = 8;        //Button for setting the Min Guide limit
int toggle = 2;              //Auto / Manual toggle switch

//Analog Pins
int knob_Pin = 6;   // Pot that controls the fast puller speed to raise the loop
int sensor_1 = 0;         //Top filament sensor
int sensor_2 = 1;      //MIddle filament sensor
int sensor_3 = 2;     //Bottom filament sensor
int sensor_4 = 3;

as you can seen the label sensor_3 meaning in the compiler the number 2.. also label toggle meaning number 2..

when you try to set the port like this

  pinMode(toggle, INPUT);
  pinMode(sensor_3, INPUT);

really you say to compiler this..

  pinMode(2, INPUT);
  pinMode(2, INPUT);

so you reset the "DIGITAL PIN" to input 2 times.. but not set the analog input.. luckily all analog port are input for default..

you have to use this

  pinMode(2, INPUT);
  pinMode(A2, INPUT);

so the label (only for setpin function) has to be A2 and not only 2..


now i'm rewriting all you firmware manner... "object oriented".. when i've done and after i've try, i'll post the firmware.

*************************

another little problem.. in the firmware that i've dowloaded...here

   if (guide_direction == 0) {               //If the current direction of the guide is forward
    if (digitalRead(12) == 1){                // If there is no jumper on Pin 12
    guide_angle = (guide_angle + 1.17); }     //Move the guide +1.17 degree for 1.75mm filament
    if (digitalRead(12) == 0){                //If there is a jumper on Pin 12
       guide_angle = (guide_angle + 1.90); }     //Move the guide 2 degrees for 3mm filament
    servo.write(guide_angle);}
    
   if (guide_direction == 1) {                //If the current direction of the guide is back
      if (digitalRead(12) == 1){              //If there is no jumper on Pin 12
    guide_angle = (guide_angle - 1.17); }     //Move the guide -1.17 degree for 1.75mm filament
     if (digitalRead(12) == 0){               //If there is a jumper on Pin 12
       guide_angle = (guide_angle + 1.90); }     //Move the guide -2 degrees for 3mm filament
     servo.write(guide_angle);}

if you seen, in the second "guide_direction" the guide_angle for the 3mm filament don't go back .. there are +1.90 where must be -1.90

6

Re: Firmware FilaWinder Study

Ian,

What's the chance of you hosting the firmware on GitHub.  That way if people find issues or have suggestions they can be tracked as issues.

It will also help people get the latest copy, or recognised if they need it.

I appreciate that this firmware is unlikely to be expected to change much, but I know you are we're experimenting with measuring diameter, etc, so I think there is still quite a bit of evolution to come.

Regards,
Craig

Masterbatch, ABS and PLA Pellets available for UK and Europe.
http://www.emakershop.com/Seller=1324

7

Re: Firmware FilaWinder Study

I'll have to look into it.  There is another version coming, as soon as I get the hang of writing int and float to EEPROM, and figure out how to pass the sensor calibration from EEPROM to the library that handles the sensors.  It would be nice not to calibrate the sensors every time, and not have a batch fail because the arduino crashed.