Steppermotor homing?

Toutes les questions sur les cartes By arpschuino
Questions about arpschuino boards
Jacques
Messages : 268
Enregistré le : dim. 31 oct. 2021 19:37

Re: Steppermotor homing?

Message par Jacques »

For now yes...
Or you would have to write your custom setup action with the zeroSwitchs directly in the stepper_setup() function of
port.cpp.
Jacques
Messages : 268
Enregistré le : dim. 31 oct. 2021 19:37

Re: Steppermotor homing?

Message par Jacques »

You can try it at the end of stepper_setup() function of
port.cpp :

Code : Tout sélectionner

   //////////////////////////////////////////////////////////
    Serial.println("Homing ...");
    uint8_t zeroSwitch0=Arp8;
    uint8_t zeroSwitch1=Arp9;
    uint8_t zeroSwitch2=Arp10;
    uint8_t zeroSwitch3=Arp11;

    pinMode(zeroSwitch0, INPUT_PULLUP);
    pinMode(zeroSwitch1, INPUT_PULLUP);
    pinMode(zeroSwitch2, INPUT_PULLUP);
    pinMode(zeroSwitch3, INPUT_PULLUP);

    m_stepper[0].refresh(255, 30);//we define a direction of rotation (255, to go in the other direction : 0), and a speed (here 30 for a slow speed) 
    m_stepper[1].refresh(255, 30);
    m_stepper[2].refresh(255, 30);
    m_stepper[3].refresh(255, 30);

    while (digitalRead(zeroSwitch0))//as long as the limit switch is not pressed ((! zeroSwitch) reverses the behavior) 
    {
        m_stepper[0].continuous();//turn !
    }

    while (digitalRead(zeroSwitch1))//as long as the limit switch is not pressed ((! zeroSwitch) reverses the behavior) 
    {
        m_stepper[1].continuous();//turn !
    }

    while (digitalRead(zeroSwitch2))//as long as the limit switch is not pressed ((! zeroSwitch) reverses the behavior) 
    {
        m_stepper[2].continuous();//turn !
    }

    while (digitalRead(zeroSwitch3))//as long as the limit switch is not pressed ((! zeroSwitch) reverses the behavior) 
    {
        m_stepper[3].continuous();//turn !
    }
        Serial.println("end of homing!");
        //////////////////////////////////////////////////////////////////////////////////
Of course set the portB as inactive mode.
Jacques
Messages : 268
Enregistré le : dim. 31 oct. 2021 19:37

Re: Steppermotor homing?

Message par Jacques »

When I click that link, I get a message that says the site can't be reached because localhost has refused the connection.
Maybe the same reason why the update tool doesn't work for me?
Sorry my link was bad ! This is the good one :
https://arpschuino.fr/telechargements_e.php
Micropuller
Messages : 47
Enregistré le : dim. 1 janv. 2023 15:55

Re: Steppermotor homing?

Message par Micropuller »

But that would mean that the program would only start if all 4 home switches are active, wouldn't it?
What if there are less than 4 motors / home switches? Wouldn't the code wait indefinately, because there are less than 4 home switches triggered?
Would it be possible to have a time-out function?
Or maybe only home motors that are active? Maybe something like this? (I have no idea if this could function)

Code : Tout sélectionner

void Port:: stepper_setup()
{ 
    uint8_t zeroSwitch0=Arp8;
    uint8_t zeroSwitch1=Arp9;
    uint8_t zeroSwitch2=Arp10;
    uint8_t zeroSwitch3=Arp11;

    for (int i=0; i < 4; ++i) 
    {           
	(zeroSwitch[i], INPUT_PULLUP);
    }

    Serial.println(" : Stepper");
    uint16_t defaultSPR = 800;
    uint16_t defaultMin = 4;
    uint16_t defaultMax = 200;
    float defaultRevol = 12;
    bool defaultAction = 0; //perform by default

    m_stepper = new ArpStepper[4];
    m_nbDmxChannels = 8;
    uint8_t startPin= (m_port_name=='A') ? 0 : 8;
    for(int i=0;i<4;i++)
    {
        String num(i);
        String str = num+"stpActive";
        const char * word = str.c_str(); 
        m_stp_active[i]= load(word,true);
        Serial.print("stepper ");  Serial.print(i); 
        if(m_stp_active[i])
        {
            str = num+"stpPerRevol"; 
            word = str.c_str(); 
            uint16_t stepPerRevolution = load(word,defaultSPR);
            //uint8_t output=i+startPin;
            m_stepper[i].attach(Arp[i*2+1+startPin],Arp[i*2+startPin],stepPerRevolution);

            Serial.print(" steps per revolution : "); Serial.print(stepPerRevolution); Serial.print("; ");  
            ////////////////////////////////////////////////////////////////////
            str = num+"_rpm_min";
            word = str.c_str();
            uint16_t rpmMin = load(word,defaultMin);
            Serial.print(" rpmmin : "); Serial.print(rpmMin); Serial.print("; "); 

            str = num+"_rpm_max";
            word = str.c_str();
            uint16_t rpmMax = load(word,defaultMax);
            Serial.print(" max : "); Serial.print(rpmMax); Serial.print("; ");   

            str = num+"_revol";
            word = str.c_str();
            float revol = load(word,defaultRevol);
            Serial.print(" revolutions : "); Serial.print(revol); Serial.print("; ");                     


            str = num+"stpAction";
            word = str.c_str();
            m_action[i] = load(word,defaultAction);
            Serial.print(" action : ");
            uint16_t dmxRes = _8bits;

            if(m_action[i]==0)
            {
                Serial.print("perform"); Serial.print("; ");
                Serial.print(" DMX resolution : ");
                str = num+"stp_dmxRes";
                word = str.c_str();
                //Serial.print("((word : ");Serial.print(word);Serial.print(" ))");//////////debug////////
                m_stp_dmxRes[i]=load(word,false);
                //Serial.print("((16bits : ");Serial.print(m_stp_dmxRes[i]);Serial.print(" ))");//////////debug////////
                if(m_stp_dmxRes[i]==true){
                    dmxRes = _16bits;
                    Serial.print("16bits"); 
                    m_nbDmxChannels++;
                } 
                else{
                    Serial.print("8bits");
                }
                Serial.print("; ");
            }
            else 
            {
                Serial.print("continuous; ") ;
            }                

            m_stepper[i].init(rpmMin, rpmMax, revol, dmxRes); 
            //Serial.println();Serial.print(" rpmMin (2): ");Serial.println(rpmMin);

            str = num+"stpInverted";
            word = str.c_str();
            bool inverted = load(word,false);
            if(inverted)
            {
                m_stepper[i].invert_rotation(true);
                Serial.println(" inverted; "); 
            }

            Serial.println("Homing ...");
            m_stepper[i].refresh(255, 30);//we define a direction of rotation (255, to go in the other direction : 0), and a speed (here 30 for a slow speed) 
        
	        while (digitalRead(zeroSwitch[i]))//as long as the limit switch is not pressed ((! zeroSwitch) reverses the behavior) 
	        {
        	m_stepper[i].continuous();//turn !
            }
            Serial.println("end of homing!");

            Serial.println(); 
        }
        else Serial.println(" inactive");
    }
    Serial.println();    
}
Modifié en dernier par Micropuller le mar. 17 janv. 2023 00:14, modifié 1 fois.
Jacques
Messages : 268
Enregistré le : dim. 31 oct. 2021 19:37

Re: Steppermotor homing?

Message par Jacques »

It should work if you define your zeroswitchs as a table :

Code : Tout sélectionner

uint8_t zeroSwitch[4]{Arp8,Arp9,Arp10,Arp11};
Micropuller
Messages : 47
Enregistré le : dim. 1 janv. 2023 15:55

Re: Steppermotor homing?

Message par Micropuller »

Ah, thanks! I just noticed that I got an error because of that.
I'm going to try this tomorrow!
Micropuller
Messages : 47
Enregistré le : dim. 1 janv. 2023 15:55

Re: Steppermotor homing?

Message par Micropuller »

Ok, another question which shows my incompetence with VSC.
I just tried to upload the altered code to the arpschuino.
The board is connected to my computer using the USB/serial programmer.
It is detected as "Silicon Labs CP210x USB to UART Bridge (COM3)"
The platformio.ini file looks like this:

Code : Tout sélectionner

; PlatformIO Project Configuration File
;
;   Build options: build flags, source filter
;   Upload options: custom upload port, speed and extra flags
;   Library options: dependencies, extra library storages
;   Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:esp32doit-devkit-v1]
platform = espressif32 @ ~5.0.0
board = esp32doit-devkit-v1
framework = arduino
monitor_speed = 115200
board_build.partitions = my_partitions.csv
monitor_rts = 0
monitor_dtr = 0
lib_deps = 
	me-no-dev/ESP Async WebServer @ ^1.2.3
	me-no-dev/AsyncTCP @ ^1.1.1
	hideakitai/ArtNet@^0.2.8
	roboticsbrno/ServoESP32@^1.0.3
	someweisguy/esp_dmx@^2.0.2

;comment for auto selection :
;upload_port = COM3
;monitor_port = COM3
When I click "Upload", it looks like it wants to connect to the arpschuino (the leds on the programmer are flickering), but then I get this error:

Code : Tout sélectionner

 *  Executing task in folder arpschuino32_1.0.1: C:\Users\Cyril\.platformio\penv\Scripts\platformio.exe run --target upload --environment esp32doit-devkit-v1 

Processing esp32doit-devkit-v1 (platform: espressif32 @ ~5.0.0; board: esp32doit-devkit-v1; framework: arduino)---------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32doit-devkit-v1.html
PLATFORM: Espressif 32 (5.0.0) > DOIT ESP32 DEVKIT V1
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
 - framework-arduinoespressif32 @ 3.20003.220626 (2.0.3)
 - tool-esptoolpy @ 1.30300.0 (3.3.0)
 - tool-mkfatfs @ 2.0.1
 - tool-mklittlefs @ 1.203.210628 (2.3)
 - tool-mkspiffs @ 2.230.0 (2.30)
 - toolchain-xtensa-esp32 @ 8.4.0+2021r2-patch3
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 41 compatible libraries
Scanning dependencies...
Dependency Graph
|-- ESP Async WebServer @ 1.2.3
|   |-- AsyncTCP @ 1.1.1
|   |-- FS @ 2.0.0
|   |-- WiFi @ 2.0.0
|-- AsyncTCP @ 1.1.1
|-- ArtNet @ 0.2.12
|   |-- SPI @ 2.0.0
|   |-- WiFi @ 2.0.0
|-- ServoESP32 @ 1.0.3
|-- esp_dmx @ 2.0.2
|-- Arpschuino
|   |-- EEPROM @ 2.0.0
|   |-- Wire @ 2.0.0
|-- arpschuino32_core
|-- Preferences @ 2.0.0
|-- ESPmDNS @ 2.0.0
|   |-- WiFi @ 2.0.0
|-- HTTPClient @ 2.0.0
|   |-- WiFi @ 2.0.0
|   |-- WiFiClientSecure @ 2.0.0
|   |   |-- WiFi @ 2.0.0
|-- Update @ 2.0.0
|-- WiFi @ 2.0.0
|-- SPIFFS @ 2.0.0
|   |-- FS @ 2.0.0
|-- ArpStepper
Building in release mode
Retrieving maximum program size .pio\build\esp32doit-devkit-v1\firmware.elf
Checking size .pio\build\esp32doit-devkit-v1\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [==        ]  15.9% (used 52132 bytes from 327680 bytes)
Flash: [========  ]  76.9% (used 1310993 bytes from 1703936 bytes)
Configuring upload protocol...
AVAILABLE: cmsis-dap, esp-bridge, esp-prog, espota, esptool, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa
CURRENT: upload_protocol = esptool
Looking for upload port...
Auto-detected: COM3
Uploading .pio\build\esp32doit-devkit-v1\firmware.bin
esptool.py v3.3
Serial port COM3
Connecting......................................

A fatal error occurred: Failed to connect to ESP32: Invalid head of packet (0x5B): Possible serial noise or corruption.
For troubleshooting steps visit: https://docs.espressif.com/projects/esptool/en/latest/troubleshooting.html    
*** [upload] Error 2
========================================= [FAILED] Took 22.33 seconds =========================================
 *  The terminal process "C:\Users\Cyril\.platformio\penv\Scripts\platformio.exe 'run', '--target', 'upload', '--environment', 'esp32doit-devkit-v1'" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it. 
What am I doing wrong?

Edit: I updated the driver for the programmer to the latest version that was available on the Silicon Labs website, but that didn't make a difference.

Edit 2: Ok, I found out I had to press the "boot" button whilst uploading the code. It seems to have worked (I can connect to the arpschuino). Tomorrow I'll test if the homing works.

Edit 3: I couldn't help myself. I connected one steppermotor and one homeswitch and it seems to be working. I had to disable the other three motors first, so that seems to work also!

Thanks for all your help!
Jacques
Messages : 268
Enregistré le : dim. 31 oct. 2021 19:37

Re: Steppermotor homing?

Message par Jacques »

Great, well done!
Keep us in touch.
Micropuller
Messages : 47
Enregistré le : dim. 1 janv. 2023 15:55

Re: Steppermotor homing?

Message par Micropuller »

Sorry to bother you again, but I'm at my wits end.

I had the home-switches working yesterday, but I had an afterthought:
I had put the code for the homing sequence all the way at the end of the stepper setup. So, if the motors would be put in continuous mode, they would also try to home. Ofcourse, that wouldn't be desireable behaivior.
So I put the homing code after the part where the motors are set to 8 bit or 16 bit. That way, only the motors that are set to be in "perform" mode, would home. I tried it this morning and it worked perfectly.

Then I started to experiment a bit with the homing speed.
I don't know what happened, but at some point the homing stopped working.

I've tried everything I could think of.
I uploaded a fresh 1.0.1 code that I downloaded through the link in this thread and inserted the stepper setup code that I posted earlier (with the zeroswitches defined as a table, like Jaques posted). I'm 100% sure that was the code that worked yesterday. But I can't get it to work anymore.

When I power on the board, the motor makes a sound like it wants to start rotating, but then the DMX led comes on and the motor reacts to the DMX signal, like there was no code for homing at all.
But when I disconnect the DMX signal and power up (or reset) the board, the motor starts rotating and does one turn (that's what I have it set to in the configuration page. So actually it does 27 turns, because I have a 27:1 reduction). It doesn't react to the input of the home switch at all.

I tried putting the homing code in several different places, but to no avail.

I also tried connecting the motor to Port B and the switch to Port A (ofcourse I also configured Port A to be inactive and Port B for steppers and changed the inputs for the endswitches to Arp0, Arp1, Arp2 and Arp3), just to be sure I hadn't blown the inputs to the microcontroller.
But every time I get the same behaviour.

Could you please have a look at the code and see if Ithere's something wrong that I'm just not seeing?

Code : Tout sélectionner

void Port:: stepper_setup()
{ 
    uint8_t zeroSwitch[4]{Arp8,Arp9,Arp10,Arp11};

    for (int i=0; i < 4; ++i) 
    {           
	(zeroSwitch[i], INPUT_PULLUP);
    }

    Serial.println(" : Stepper");
    uint16_t defaultSPR = 800;
    uint16_t defaultMin = 4;
    uint16_t defaultMax = 200;
    float defaultRevol = 12;
    bool defaultAction = 0; //perform by default    

    m_stepper = new ArpStepper[4];
    m_nbDmxChannels = 8;
    uint8_t startPin= (m_port_name=='A') ? 0 : 8;

    for(int i=0;i<4;i++)
    {
        String num(i);
        String str = num+"stpActive";
        const char * word = str.c_str(); 
        m_stp_active[i]= load(word,true);
        Serial.print("stepper ");  Serial.print(i); 

        if(m_stp_active[i])
        {
            str = num+"stpPerRevol"; 
            word = str.c_str(); 
            uint16_t stepPerRevolution = load(word,defaultSPR);
            //uint8_t output=i+startPin;
            m_stepper[i].attach(Arp[i*2+1+startPin],Arp[i*2+startPin],stepPerRevolution);

            Serial.print(" steps per revolution : "); Serial.print(stepPerRevolution); Serial.print("; ");  
            ////////////////////////////////////////////////////////////////////
            str = num+"_rpm_min";
            word = str.c_str();
            uint16_t rpmMin = load(word,defaultMin);
            Serial.print(" rpmmin : "); Serial.print(rpmMin); Serial.print("; "); 

            str = num+"_rpm_max";
            word = str.c_str();
            uint16_t rpmMax = load(word,defaultMax);
            Serial.print(" max : "); Serial.print(rpmMax); Serial.print("; ");   

            str = num+"_revol";
            word = str.c_str();
            float revol = load(word,defaultRevol);
            Serial.print(" revolutions : "); Serial.print(revol); Serial.print("; "); 

            str = num+"stpAction";
            word = str.c_str();
            m_action[i] = load(word,defaultAction);
            Serial.print(" action : ");
            uint16_t dmxRes = _8bits;

            if(m_action[i]==0)
            {
                Serial.print("perform"); Serial.print("; ");
                Serial.print(" DMX resolution : ");
                str = num+"stp_dmxRes";
                word = str.c_str();
                //Serial.print("((word : ");Serial.print(word);Serial.print(" ))");//////////debug////////
                m_stp_dmxRes[i]=load(word,false);
                //Serial.print("((16bits : ");Serial.print(m_stp_dmxRes[i]);Serial.print(" ))");//////////debug////////
                
                if(m_stp_dmxRes[i]==true)
                {
                    dmxRes = _16bits;
                    Serial.print("16bits"); 
                    m_nbDmxChannels++;
                }

                else
                {
                    Serial.print("8bits");
                }

                Serial.print("; ");   

                Serial.println("Homing ...");
                m_stepper[i].refresh(255, 10);//we define a direction of rotation (255, to go in the other direction : 0), and a speed (here 30 for a slow speed)

                while (digitalRead(zeroSwitch[i]))//as long as the limit switch is not pressed ((! zeroSwitch) reverses the behavior)
                {
                    m_stepper[i].continuous();//turn !
                }

                Serial.println("end of homing!");           
            }

            else 
            {
                Serial.print("continuous; ") ;
            }                

            m_stepper[i].init(rpmMin, rpmMax, revol, dmxRes); 
            //Serial.println();Serial.print(" rpmMin (2): ");Serial.println(rpmMin);

            str = num+"stpInverted";
            word = str.c_str();
            bool inverted = load(word,false);
            
            if(inverted)
            {
                m_stepper[i].invert_rotation(true);
                Serial.println(" inverted; ");                 
            }
            
            Serial.println(); 
        }
        else Serial.println(" inactive");
    }
    Serial.println();    
}
Jacques
Messages : 268
Enregistré le : dim. 31 oct. 2021 19:37

Re: Steppermotor homing?

Message par Jacques »

Don't bother, no problem!
I think you shouldn't mix the original code with the additional code. Leave the setup intact and then just add the homing code.
To your working code just add a check, or rather a double check.
Is my stepper active?
Is my stepper in perform mode?
It gives something like this :

Code : Tout sélectionner

    Serial.println("Homing ...");
    uint8_t zeroSwitch[4]{Arp8,Arp9,Arp10,Arp11};
    for (int i=0; i < 4; ++i) 
    {           
	pinMode(zeroSwitch[i], INPUT_PULLUP);
        m_stepper[0].refresh(255, 30);//we define a direction of rotation (255, to go in the other direction : 0), and a speed (here 30 for a slow speed) 
        if (m_stp_active[i]==true && m_action[i]==0) //m_action[i]==0 mean perform mode
        {
            while (digitalRead(zeroSwitch[i]))//as long as the limit switch is not pressed ((! zeroSwitch) reverses the behavior) 
            {
                m_stepper[i].continuous();//turn !
            }          
        }
    }
    Serial.println("end of homing!");
Répondre