Use a variable to control the Little Step-U
Podion
Posts: 90
Hello.
Im working in a project whit the Little Step-U (ID27938) and the Propeller. My project is to control the Little Step-U whit data that came from a variable. The variable is from 0 to 255 it' came from the #ADC0831 whit a 10K POT that is plug to the propeller. I want to control the step motor position whit the 10K POT and the #ADC0831 so 0 = position 0 , 255 = one full rotation and 127,5 = half rotation etc.
My problem is that i dont find a way to send my variable to the Little Step-U. The code to send position data is
I put the code line in red were is my problemStep + Pot = position - Archive [Date 2014.01.15 Time 10.45].zip
Thank you for your help
PODion
Im working in a project whit the Little Step-U (ID27938) and the Propeller. My project is to control the Little Step-U whit data that came from a variable. The variable is from 0 to 255 it' came from the #ADC0831 whit a 10K POT that is plug to the propeller. I want to control the step motor position whit the 10K POT and the #ADC0831 so 0 = position 0 , 255 = one full rotation and 127,5 = half rotation etc.
My problem is that i dont find a way to send my variable to the Little Step-U. The code to send position data is
Stepper.str(string([COLOR=#ff0000]"{D1000}"[/COLOR]))( that code make the step motor to move at the absolute position 1000 ) it dont seams that i can't replace the "{D1000}" whit the variable of my choice. Do you have any idea how can I do this?
I put the code line in red were is my problemStep + Pot = position - Archive [Date 2014.01.15 Time 10.45].zip
Thank you for your help
PODion
{{ ADC_0831_DEMO.spin - 1.0 - January 2008 ┌──────────────────────────────────────────┐ │ Copyright (c) 2008 Jean-Marc Lugrin │ │ See end of file for terms of use. │ └──────────────────────────────────────────┘ *********************************************************************** Based on an example of Larry Freeze September 2007 (Obex, ADC0831 LM34) Largely adapted (and hopefully clarified for beginners) by Jean-Marc Lugrin January 2008 *********************************************************************** The ADC0831 is an 8 bit single input ADC, very simple to use. This code demonstrate how to read values from the ADC. It is is simply displayed using FullDuplexSerial, for example on PropTerm or any terminal emulator. This code is intended to be a demonstration for beginners. It is based from an example kindly provided by Larry Freeze, but I adaped it to be easier to understand and use (at least this is what I think). You may want to refer to the datasheet of the ADC0831 to understand the logic of the code, especially the figure on ADC0831 timing. The demo connection I used is as follow (the pin are different from the original code, but you can change them at will): ADC0831 │ Vcc(+5V) ┌───────────────┐ │ pin 17 ────┤1 -CS VCC 8 ├───┘ ┌────┤2 VIN+ CLK 7 ├───────── pin 16 │ ┌─┤3 VIN- DO 6 ├─────── pin 18 (1K resistor) │ ╋─┤4 GND Vref 5 ├───────┐ │  └───────────────┘ │  │ ┌────────────────────────────┻─ +3.3V (or 5V)  10K The potentiometer AND the Vref could be connected to the +5V also. Value of the potentiometre is not critical. In practice I connected ALL lines to the propeller via a 2.2K resistors, to be on the safe side. The purpose of this object is to repeatedly read and display the position of the ptoentiometer on the desktop monitor, via a hyperterminal or PropTerm connection (see Parallax Propeller Forums or OBEX to get PropTerm). This object is a template, the code to control an ADC0831 is simple enough that it is easy to adapt to your needs or extend if required. NOTE : No delay is used to control the pulse width, as the ADC0831 is assumed to follow Spin (which takes quite a few uSec per statements. Max conversion rate is about 2.5KHz for a clock of 80 Mhz. I have used these pins and connections in this object. ADC clk PIN 7 to propeller PIN 16 (preferably through 1K resistor) ADC cs PIN 1 to propeller PIN 17 (preferably through 1K resistor) ADC do PIN 2 to propeller PIN 18 (through 1K resistor) }} CON _clkmode = xtal1 + pll16x ' The code works at any frequency, but the serial line requires the crystal _xinfreq = 5_000_000 ' Define the pins. This could be adapted for example to be a set of variable initialized ' by a function, so that the object can be used with multiple ADC CLK_PIN = 16 CS_BAR_PIN = 17 ' 'BAR' To remind you that this is an active low pin (idle state is high) DO_PIN = 18 ' Configuration only required for the example serial output RX_PIN = 31 TX_PIN = 30 BAUD_RATE = 9600 OBJ Stepper: "Extended_FDSerial" VAR Pub Start | data dira[0..1]~~ outa[0..1]~~ 'Prop PIN 0 for Pulse  Little-Step-U IP1 Stepper.start(11,10,1,2400) 'rx pin,tx pin,mode,baud rate for Little-Step-U Stepper.str(string("{S}")) 'SWITCH TO REMOTE MODE waitcnt(clkfreq +cnt) Stepper.str(string("{Q}")) ' Initialiszation section initialize repeat ' Acquire 1 measurement data := AcquireValue ' At this point the value of 'data' is between 0 and 255 PulseValue(data) PUB Initialize {{ Initialize the pins direction and state. Must be called once. }} dira[DO_PIN]~ ' set DO pin as input (is default at start, present for clarity) outa[CS_BAR_PIN]~~ ' sets pin -CS high (you must always first set the value, then enable the output!) dira[CS_BAR_PIN]~~ ' sets -CS pin as output (this means disabled !) outa[CLK_PIN]~ ' sets clock pin low (is default at start, present for clarity) dira[CLK_PIN]~~ ' sets pin as output PRI AcquireValue | data ' data could also be a byte VARiable {{ Aquiring data requires to assert CS, pulse the clock once to start aquisition, then pulse the clock 8 times to read each bit after the descending edge of the clock. The chip is driven by the clock signal we generate, so timing is not critical. }} data := 0 ' This will accumulate the resulting value outa[CS_BAR_PIN]~ ' sets pin -CS low to activate the chip outa[CLK_PIN]~~ ' pulse the clock, first high outa[CLK_PIN]~ ' then low, this starts the conversion 'Read 8 bits, MSB first. ' Althoug the datasheet I have says that LSB is not available on the ADC0831, it is present on my chip repeat 8 data <<= 1 ' Multiply data by two outa[CLK_PIN]~~ ' pulse the clock, first high outa[CLK_PIN]~ ' then low, this makes the next bit available on DO data += ina[DO_PIN] ' Add it to the current value outa[CS_BAR_PIN]~~ ' Terminated, deselect the chip return data PUB PulseValue(value) Stepper.str(string( "{D1000}")) ' [COLOR=#ff0000]there is the place that i want to put the value variable[/COLOR] {{ ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ │ TERMS OF USE: MIT License │ ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation │ │files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, │ │modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software│ │is furnished to do so, subject to the following conditions: │ │ │ │The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.│ │ │ │THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE │ │WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR │ │COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │ │ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │ └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ }}
Comments
So i need to find an other way to send data to the Little Step-U that the Stepper.str(string method
Do you have an idea how ti send {D1000} or {variable_value} whiteout " "
Thank you
27938-Little-StepU-Manual.pdf