B4R Code Snippet driving xy stepmotors by single byte

driving two motors (x,y) with 16 steps can be realized by one byte orders (16 stepmodes in upper 4 bit, 16 in lower 4 bit)

as never two same states follow each other, two same bytes in follow can be recognized as exit of one byte mode.

16 steps means, a stepper with 50 stages has 800 steps for one turnaround - the 16 steps realize 4 pole modes ( ++ +- -- -+ ) within 4 power modes for xAB and yAB windings between steps - for smooth running and high resolution. For instance for use of SMC1500:
https://www.conrad.de/de/steuerkarte-emis-smc-1500-24-vdc-15-a-967785.html


B4X:
 '(thanks, Erel...)
process globals
    Dim singleByteMode As Boolean
    Dim singleByteFirst As Boolean = True
    Dim singleByteIn As Int
    Dim singleByteLastIn As Int
end sub

private Sub Astream_NewData(Buffer() As Byte)
    If singleByteMode = True Then
          singleByteIn = bc.StringFromBytes(Buffer)
          If singleByteIn= singleByteLastIn And singleByteFirst = False Then ' exit single byte mode
            singleByteMode = False ' exit at same byte
            log("singleByteMode false")
            singleByteFirst = True
            return
          End If
          singleByteFirst = False ' ignore first
          singleByteLastIn = singleByteIn
          Return
    End If

    If bc.StartsWith(Buffer,"<s:".GetBytes)  Then ' start single byte mode - "<s:" as order
        singleByteMode = True
        log("singleByteMode true")
        Return
    End If
end sub

in case of interest, I can post the motor steering sequence too...
 
Last edited:

Hans- Joachim Krahe

Active Member
Licensed User
Longtime User
visual basic. my app once translates exports from 3DSMAX for 3d Objects, I can burn with plasma and weld then. Second Import is from Adobe Indesign for 2D Graphs - graphics, tried dry point etching, but not so successfull...
 

Hans- Joachim Krahe

Active Member
Licensed User
Longtime User
b4r_qumram.jpg
 

Hans- Joachim Krahe

Active Member
Licensed User
Longtime User
If you were using B4J then the simplest way to send data is with B4RSerializator: https://www.b4x.com/android/forum/threads/72404/#content


hm, I need a time control between sending bytes. The times between steps are changing in case of steering because of the inertia of the printerhead, that can be heavy. Sending simply bytes seems to me as the most direct way of steering, but I'll check it out. so many thanks for your help, hope to be much more efficient with arduino, than with expensive parallax and confusing CControl before:)
 

Hans- Joachim Krahe

Active Member
Licensed User
Longtime User
If you were using B4J then the simplest way to send data is with B4RSerializator: https://www.b4x.com/android/forum/threads/72404/#content
.. using b4j means, to transfer about 8000 rows of code, even such, that works with complex Windows grafics. Guess, I'm too old therefor:) if I cannot transfer Objects with one byte, I'll try to compress routing and redundance to 6 bit - 3 bit 8 direction routing, 1 bit x y selection, 2 bit for last bits of motorstate-control.A character is sometimes good enough..Lets try:)


...single step works now smooth with about 1000 steps a second. Not much, but good enough...
 
Last edited:
Top