Shop OBEX P1 Docs P2 Docs Learn Events
Announcing the release of the Arduino LIGHT object — Parallax Forums

Announcing the release of the Arduino LIGHT object

pedwardpedward Posts: 1,642
edited 2011-11-29 22:30 in Propeller 1
I have completed implementing most of the Arduino SDK and call it Arduino LIGHT (http://obex.parallax.com/objects/810/). I refer to it as _light_ because it doesn't try to be a faithful re-implementation of the Arduino SDK, but rather a bridge that will help and encourage Arduinites in their exploration of the Propeller.

The object has documentation which states exactly what the differences are between the Arduino and the SPIN object. My hope is to help those programmers who wish to explore the Propeller and are acquainted with the Arduino ecosystem. It can be very daunting for a newbie in Propeller land to get their head wrapped around all the different objects and concepts. This is in stark contrast to the very tidy and simple Arduino environment, with the limited number of pins, simple I/O abstraction, and brief but powerful SDK.

For reference, here are all of the implemented SDK functions (aside from language constructs):

  • Pins
    • pinMode()
    • digitalWrite()
    • digitalRead()
  • Time
    • millis()
    • micros()
    • delay()
    • delayMicroseconds()
  • Math
    • _min()
    • _max()
    • _abs()
    • constrain()
    • map()
    • pow()
    • sqrt()
    • sin()
    • cos()
    • tan()
  • Bits and Bytes
    • lowByte()
    • highByte()
    • bitRead()
    • bitWrite()
    • bitSet()
    • bitClear()
    • bit()
  • Advanced I/O
    • tone()
    • noTone()
    • shiftIn()
    • shiftOut()
    • pulseIn()
  • Analog I/O
    • analogWrite()
  • RandomNumbers
    • randomSeed()
    • random()

Here is a copy of the comment section from the SPIN file, with some important comments about the implementation:
This object is a SPIN interface to emulate the Arduino SDK functions.

These methods are intended to make it easier for developers familiar
with Arduino to start using the Propeller. I highly recommend that
you own the _Propeller Manual_ ISBN# 9781928982470 in hardcopy. You
can download the PDF version from the Parallax website.

These functions are entirely written in SPIN, absent any ASM. Where
it makes sense, functions are written long hand for readability,
however some of the operations use SPIN shorthand conventions because
they are more convenient than the standard C notation.

There are a lot of objects on OBEX (http://obex.parallax.com) which
implement many of the Arduino functions in a native manner, with higher
performance. I highly recommend perusing the demos and objects included
in the Propeller Development Kit download.

Some objects I recommend reviewing:

FullDuplexSerial
Simple_Serial
Parallax Serial Terminal
Float32
SDCard Full Filesystem Driver (http://obex.parallax.com/objects/619/)
ADC
CTR
MCP3208
SPI_Spin -or- SPI_Asm
VGA -and- VGA_Text
TV -and- TV_Text -and- TV_Terminal

This is considered the _light_ version, which does not require a
supervisory COG. The caveat to the _light_ version is that some
functions do not operate exactly like the Arduino.

Differences between this _light_ implementation and the Arduino:

millis() and micros() overflow every ~54 seconds because the system
counter runs at clock speed (usually 80Mhz) and is 32 bits

tone() does not have a duration option, so you must call noTone() to turn
off the output. This function also accepts values larger than 65536.

digitalWrite() does not operate at 500Hz, it uses a hardware counter that
operates at the main clock frequency, which is usually 80Mhz.

pow() is integer only, it does not accept or return float types, see
the Float32A object

sqrt() is integer only, see Float32A

attachInterrupt(), detachInterrupt(), interrupts(), and noInterrupts()
are not implemented because the Propeller does not have interrupts.
Propeller programming convention is to use multiple COGs where you might
have used interrupts in a conventional mCu architecture.

sin(), cos(), and tan() take degrees and radius, instead of radians. This
format does not require degree to radian conversion and subsequent radius
multiplication. The result is a signed value with a range of +- radius.

analogRead() and analogReference() are not implemented, the Propeller does
not have embedded AtoD hardware, either an external ADC chip is needed or
you can use Sigma-Delta AtoD conversion. The ADC SPIN object implements
sigma delta ADC conversion, the MCP3208 object interfaces to an
external ADC chip via SPI.
Sign In or Register to comment.