User Tools

Site Tools


HAM Radio Controller with the Raspberry PI

Programming examples

the following examples should show how super easy the programming is. Thanks to the many prepared functions, even complex applications can be written quickly.

The programming is done in C language with the normal board tools of a Raspberry PI, without special libraries.

Controlling a Stepper Motor

In this example the rotation of a rotary encoder is output directly to a stepper motor:

    // assign two input ports to the rotary encoder
    init_rotencoder(KEY0, KEY1, -1,-1,-1,-1);
    // assign ports for step and direction to the stepper motor PA
    int stepid = create_stepper(OUT0, OUT1, OUT2, 0, 10, -1, -1);
    while(1)                          // endless loop
        int steps = getEncSteps(0);   // read Encoder
                                      // if the encoder was actuated
                                      // Output the number of steps to the stepper motor PA
        if(steps != 0) move_stepper(stepid,abs(steps),(steps>0)?1:0,1);

3D stepper motor controller for 3 axes

same example as before, but for three axes

    // assign two input ports each to the three rotary encoders
    init_rotencoder(KEY0, KEY1, KEY2, KEY3, IN4, IN5);
    // assign the three stepper motor PA ports for step and direction
    int stepidX = create_stepper(OUT0, OUT1, OUT2, 0, 10, -1, -1);
    int stepidY = create_stepper(OUT3, OUT4, OUT5, 0, 10, -1, -1);
    int stepidZ = create_stepper(OUT6, OUT7, OUT8, 0, 10, -1, -1);
    while(1)                          // endless loop
        int stepsX = getEncSteps(0);
        int stepsY = getEncSteps(1);
        int stepsZ = getEncSteps(2);
        if(stepsX != 0) move_stepper(stepidX,abs(stepsX),(stepsX>0)?1:0,1);
        if(stepsY != 0) move_stepper(stepidY,abs(stepsY),(stepsY>0)?1:0,1);
        if(stepsZ != 0) move_stepper(stepidZ,abs(stepsZ),(stepsZ>0)?1:0,1);

showing the actual sun position

    gps_open(NULL, NULL, B4800); // use serial IF on RPI board
        int az, elev;
        getSunPos(&az, &elev);
        char text[200];
        sprintf(s,"Sun is at azimuth:%d deg and elevation:%d deg",az,elev);
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
en/rpictlbrd/ctlbrd_examples.txt ยท Last modified: 2021/04/20 01:40 by kurt