Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8435397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:54:14+00:00 2026-06-10T06:54:14+00:00

Hello I’m a newbie with Python but I’ve been interested on it for 2

  • 0

Hello I’m a newbie with Python but I’ve been interested on it for 2 years. I want to make robots and I’m trying to use Python with pyserial on blender. But I found a problem and after 2 hours of looking for the answer in Google and in this site I found that maybe I’m retarded because I can’t solve it. I think it isn’t asked yet.

I’m using a devantech sd84 servo controller and controling it via a USB port a serial device so I use pyserial. The problem is that I want Python to take a decimal value fom a user input between 400–2200 and I know how to do it but I need Python to show it as two bytes and send the low byte first and then the high byte. for example (pseudo code as I don’t how to program it yet):

    #ask for a decimal number between a range (the range does not really matters)
    x = raw_input('\tInsert a number between 400-2200:') #Insert a number between 400-2200: 1500
    #show it as hex
    hex(x) #5dc
    #put it in two bytes and in this case add a zero(?) I don't know how to do that.
    0xDC 0x05
    #add it to a 16-bit integer to send it to the servo controller via the virtual serial port(?) i also don't know how to do that. 
   ser.write('\xAA\xA0\x55\x01\x01\x02\xDC\x05')

For the interest of people who have the same controler I’ll explane that 16bit integer first three bytes are sync (\xAA\xA0\x55) then the type of command SET_SERVO (position) (\x01) then the channel 1-84 for 1 is (\x01) then a byte count in this case 2 (\x02) and the servo position low byte and then the high byte (\xDC\x05) which nowadays I calculate with in my iPod with an app and then I insert manually hahaha I want to stop whith that stupid thing and let he compuer do it for me.

Now I will post a code I made for testing purposes it mades a servo in channel 1 go troug it’s full range ata different speeds and print funny things in spanish while the servo “dances” I manually calculated the positons and inserted them hahaha sounds like history for me.

    # -*- coding: utf-8 -*-
    #Pablo P. 2012 "bailecillo"
    #mueve un servo en el canal 1 a través de todo su recorido e imprime frases mientras dicho servo "baila"
    import serial
    import time
    # Para cambiar de Sistema Operativo cambiar puerto 
    #en la siguiente línea: Win COM# linux /dev/ttyS# /dev/ttyUSB#
    # #=un número asignado por tu sistema.
    port='COM3'
    sync='\xAA\xA0\x55'
    SET_SERVO='\x01'
    GET_SERVO='\x02'
    SET_SPEED='\x03'
    SET_MODE='\x04'
    GET_MODE='\x05'
    SET_AD_CNT='\x06' #Controla el número de canales analógicos.
    GET_AD_CNT='\x07' #Devuelve el número de canales analógicos actuales.
    GET_INPUT='\X08' # Devuelve el estado de una entrada.
    GET_ADC='\X09' #Devuelve el valor de un canal analógico.
    GET_VERSION='\x0A' #Devuelve la versión del procesador seleccionado.
    GET_BULK='\x15' #Usado para test en fábriica.
    TEST='\X16' #Usado para test en fábrica.
    ser = serial.Serial(port, baudrate=115200, bytesize=8, parity='N', stopbits=2,timeout=1)

   print "Hola! me alegro de verte."
   time.sleep(2)

   if ser.isOpen():
print "Estado del puerto: Correcto."
time.sleep(1)
print "Procedo a enviar modo del canal 1 y posicion(es) del mismo."
time.sleep(3)
print "Comprobando sistemas de baile..."
ser.write(sync+SET_MODE+'\x01\x01\x19')
ser.write(sync+SET_SERVO+'\x01\x02\x98\x08') #izda
time.sleep(3)
ser.write(sync+SET_SERVO+'\x01\x02\x90\x01') #derecha
time.sleep(1)
ser.write(sync+SET_SPEED+'\x01\x01\x10')
ser.write(sync+SET_SERVO+'\x01\x02\x78\x05') #centro
time.sleep(2)
print "Vamos a bailar!"
time.sleep(2)
print "preparados..."
time.sleep(1)
print "listos..."
time.sleep(1)
print "Yaaaa!!"
ser.write(sync+SET_SERVO+'\x01\x02\x98\x08') #izda
time.sleep(3)
ser.write(sync+SET_SERVO+'\x01\x02\x90\x01') #derecha
time.sleep(3)
ser.write(sync+SET_SERVO+'\x01\x02\x98\x08') #izda
time.sleep(3)
ser.write(sync+SET_SERVO+'\x01\x02\x90\x01') #derecha
time.sleep(3)
ser.write(sync+SET_SERVO+'\x01\x02\x98\x08') #izda
time.sleep(3)
ser.write(sync+SET_SERVO+'\x01\x02\x90\x01') #derecha
time.sleep(3)
ser.write(sync+SET_SERVO+'\x01\x02\x78\x05') #centro
time.sleep(3)
ser.write(sync+SET_SPEED+'\x01\x01\x00')
ser.close()
time.sleep(1)
print "Todo el proceso completado correctamente."

    else:
        print "El puertito está cerrado"

    print "Hasta Luego :D"
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:54:16+00:00Added an answer on June 10, 2026 at 6:54 am

    This is why programmers new to Python should look over the libref.

    >>> struct.pack('<h', 1500)
    '\xdc\x05'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello! I've been programming for a long time but just started developing for android,
hello friends i am trying to get a list of user id and want
Hello fellow developers... just to make sure, I want to ask this question: How
. Hello, I am trying to make a Custom Segue for my storyboard. Now
Hello i been trying to get a tokenizer to work using the boost library
Hello i want to get simple list fragment example i have searched out but
Hello i'm trying to test GStreamer on OpenSuse 11.4, to display a webcam, but
Hello, I want to put custom status bar in notification window of iphone. is
Hello all I am working on javascript jquery and svg.I want to ask a
Hello everyone i am trying to format the input number range with php number_format

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.