Shop OBEX P1 Docs P2 Docs Learn Events
Device IO Library — Parallax Forums

Device IO Library

blittledblittled Posts: 681
edited 2012-01-09 18:29 in Propeller 1
In building some demos I see myself repeating routines especially in masking bits so I thought a library of functions would be useful. The code would be in C, no assembly, so some functions maybe somewhat slow but portable between most memory models and also independent of board type. Most of the routines are built from other functions in the library and is modeled after the BS2_Functions. Right now I have the following:

void Out(int pin, int state)
This sets DIRA for the pin as an output then sets it to state.

int In(int pin)
This sets DIRA for the pin as an input and returns the state of input

void Delay(uint32_t duration)
This waits duration counts of CLK.

void Pulse(int pin, int state, uint32_t duration)
This pulses a pin for duration counts at the state designated then sets the pin to the opposite state

I'm now working on shiftin and shiftout on a pin.

I have plans for PWMPin, FreqOut, CountPulses, SerOut, SerIn, I2CWrite, I2CRead, SPIByte, SPIWord, SPILong.

Does anyone have any other suggestions?

My primary goal with this is to provide code examples for beginning C programmers and have functions that make the transition from SPIN to C easier. I also plan on coding some demos that use the library. Due to the holidays my schedule is a bit busy. I'm squeezing in time for this project when I can so it may be a little while before it is finished.

Comments

  • blittledblittled Posts: 681
    edited 2011-11-27 19:45
    Reserved for updates
  • jazzedjazzed Posts: 11,803
    edited 2011-11-27 20:34
    Maybe we should port the arduino library?
    I haven't really looked at the effort required to port the library.
    It's all open source and has some of the same function names.

    Having a simple library like you mention has value too.
    I'm not trying to dissuade you as any effort is appreciated.
  • Martin HodgeMartin Hodge Posts: 1,246
    edited 2011-11-27 22:44
    jazzed wrote: »
    Maybe we should port the arduino library?
    I haven't really looked at the effort required to port the library.
    It's all open source and has some of the same function names.

    Enthusiastic second on this idea! I'm eager to provide what resources I can to help in this effort.
  • ReinhardReinhard Posts: 489
    edited 2011-11-27 23:45
    Have an old Lego Mindstorm system set.

    Maybe it's a good idea to port the LegOS, with lib functions like

    void PlaySound(int frequency, int duration)

    void motor_a_dir (MotorDirection dir)

    void motor_a_speed(unsigned char speed)

    wakeup_t wait_event ((*'wakeup) ......)

    That are all functions for robotic environment, what's the forum think about this , replace the Brick with an propeller board ?
  • graffixgraffix Posts: 389
    edited 2011-11-28 00:16
    interesting,I hadnt thought of that " replace the Brick with an propeller board ?"
    some nice sensors in the lego kit
  • ReinhardReinhard Posts: 489
    edited 2011-11-28 10:07
    Years ago, I played with the Lego Mindstorm kit.
    In this time I used the LegOS instead the original Operating System.

    I must search this old stuff, because today I have no idea about the Memory Size.
    Maybe it's too large for the hub, but perhaps any can make a tailor made solution.

    I'll go back if I found more details.

    Reinhard
  • ReinhardReinhard Posts: 489
    edited 2011-11-28 10:21
    Btw.

    I think the IO Lib from bittled, will be a good base for any project.

    With the Arduino I am not so familiar, so I can nothing say about it.

    Reinhard
  • ReinhardReinhard Posts: 489
    edited 2011-11-29 11:03
    Hi,

    Will give a small input for library.
    For analog input reading with a SigmaDelta ADC, according to Parallax AN008,
    here is the C version.

    best regards
    Reinhard
  • ReinhardReinhard Posts: 489
    edited 2011-12-01 00:51
    Reinhard wrote: »
    Years ago, I played with the Lego Mindstorm kit.
    In this time I used the LegOS instead the original Operating System.

    I must search this old stuff, because today I have no idea about the Memory Size.
    Maybe it's too large for the hub, but perhaps any can make a tailor made solution.

    I'll go back if I found more details.

    Reinhard

    The RCX1.0 has a Hitachi H8 µC with 32 kB RAM.
    So I start with the Robot Library.
    First Implementation include

    void setMotorPower (Motor motor, Power percent); // motor = A | B | C percent = 0 .. 100
    void setMotorDirection (Motor motor, Direction dir); // dir = fwd | back

    I build a Breadboard with an Propstick/USB and own electronic circuit driver for the origin Lego motors / sensors.

    Will present if finished, maybe after xmas holidays.

    best regards
    Reinhard
  • ReinhardReinhard Posts: 489
    edited 2011-12-01 16:41
    Hi,
    the Robot Project makes good progress.

    Today afternoon I build first prototype, looks like this:

    Pinning: Controlled by needed Header

    P0 currently unused
    P1 currently unused
    P2 currently unused
    P3 AnalogOut Duty Cycle Method Cog0 analog_out.h
    P4 MotorB direction Digital Out Cog0 motor.h / kernel.h
    P5 MotorA direction Digital Out Cog0 motor.h / kernel.h
    P6 MotorB Power PWM Cog1 motor.h / kernel.h
    P7 MotorA Power PWM Cog2 motor.h / kernel.h
    P8/P9 AnalogInSlow SigmaDelta Cog3 kernel.h
    P10 currently unused
    P11 currently unused
    P12 currently unused
    P13 currently unused
    P14 currently unused
    P15 currently unused
    P16 LED DigitalOut Cog0
    P17 currently unused
    P18 currently unused
    P19 currently unused
    P20 currently unused
    P21 currently unused
    P22 currently unused
    P23 currently unused
    P24 currently unused
    P25 currently unused
    P26 currently unused
    P27 currently unused

    P28 SCL EEPROM
    P29 SDA EEPROM
    P30 RXD USB
    P31 TXD USB

    Planned:
    ADC_Fast MAX147 via 4 wire Interface
    LCD_Display Hitachi LCD Interface
    Sound_OUT Play a Melody
    Touch Sensor Digital IN

    LightSensor Channel 0 of MAX 147
    IR Sensor Channel 1 of MAX 147
    Hall Sensor Channel 2 of MAX 147

    best regards,
    Reinhard
  • jazzedjazzed Posts: 11,803
    edited 2011-12-02 00:06
    Reinhart, this looks like a great start. I'll have to look for my old Mindstorms brick.
  • blittledblittled Posts: 681
    edited 2011-12-10 19:46
    I've been a bit quiet on the forum so I thought I'd update everyone on my progress. The library is proceeding nicely. It is a bit slow going since so far I build each function on previously written functions which have gone through testing. It also has been a good review for me since I'm trying macros and structures. So far I got functions for setting and clearing bits, controlling individual bits on DIRA, OUTA and INA, Pulse a output (either a high or low pulse), Delay, Shift In and Shift Out. The devices I have used successfully with these functions are led, switch, Parallax 5 way switch, trackball, NES controller and DS1302 clock.

    The Shift In and Shift Out use a clock that should be about 40kHz. I'll verify it with an oscilloscope. I may be able to tweak it for a faster speed.

    I am now working with I2C functions and plan on developing SPI and Serial protocols. Then I'll concentrate on the cog clocks so I can produce PWM, Pulse width measurement and measuring time between pulses.

    Once these are done I'll zip up the library with all my test programs to devices as demos and a pdf describing the library functions and demos.

    After that I'll probably rewrite the pdf as a tutorial teaching how to transition from Spin to C. And if I feel ambitious :) I'll rewrite the code in C++.
  • ersmithersmith Posts: 6,099
    edited 2011-12-11 04:04
    Sounds great! I'm looking forward to looking at the library.

    Cheers,
    Eric
  • blittledblittled Posts: 681
    edited 2012-01-09 18:29
    Just an update... I have I2C working and now I'll be writing SPI functions. I didn't get much done during the holidays due to illnesses in the family. Now that everone is fine I can get back to coding c :).
Sign In or Register to comment.