Arduino programing in Fatdog64

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
Uten
Posts: 129
Joined: Tue 29 Jan 2008, 11:00

Arduino programing in Fatdog64

#1 Post by Uten »

This is how I got my first arduino program up and running from fatdog64. I suppose the procedure should work on all resent puppy derivatives with a little tinkering.

Forget about the fancy IDE approach. To me it was a dead end because of dependencies. And we all love Geany, vim and the terminal anyway, don't we..:o)

The tool we need is platformio core
SOURCE: http://platformio.org/get-started/cli
First you need to load your devx. On Fatdog64 you can load it with

Code: Select all

load_sfs.sh --load <path>/*devx*.sfs
I can't remember if any other puppy has load_sfs.sh but normally you can load and unload a devx from ROX.

Then we need pip ( https://en.wikipedia.org/wiki/Pip_%28package_manager%29 )

Code: Select all

wget -qO- https://bootstrap.pypa.io/get-pip.py | python
Then we need to update setuptools

Code: Select all

pip install setuptools
And then we get platformio

Code: Select all

pip install -U platformio
To make platformio happy (it worked without, but) we get som udev rules

Code: Select all

cd /etc/udev/rules.d/
wget https://github.com/platformio/platformio-core/blob/develop/scripts/99-platformio-udev.rules
Now lets do a test.

Code: Select all

command -v platformio
If it returns platformio the program is found and is executable.

Get a list of supported boards

Code: Select all

platformio boards
Lets see if our board are found automatically

Code: Select all

platformio device list
On my system the command returned:

Code: Select all

/dev/ttyUSB0
------------
Hardware ID: USB VID:PID=1A86:7523 LOCATION=1-8.4
Description: USB2.0-Serial

Make a simple project

Code: Select all

mkdir /tmp/test_project
cd /tmp/test_project
platformio init --board uno
Make the obligatory hello world blink application

Code: Select all

geany src/main.c
And use something like

Code: Select all

/**
 * Blink
 *
 * Turns the L LED on and off
 */
#include "Arduino.h"

#ifndef LED_BUILTIN
#define LED_BUILTIN 13
#endif

void setup()
{
  // initialize LED digital pin as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop()
{
  // turn the LED on (HIGH is the voltage level)
  digitalWrite(LED_BUILTIN, HIGH);

  // wait for a second
  delay(1000);

  // turn the LED off by making the voltage LOW
  digitalWrite(LED_BUILTIN, LOW);

   // wait for a second
  delay(3000);
}
Test the project

Code: Select all

platformio run
If we have success upload the code

Code: Select all

platformio run -t upload

I think that is basically it.. As I use to do I wrapt it up in an sfs and that one came in at 6.5M. That is quite a lot less than the IDE alternatives out there.

As arduino is unfamiliar terrain to me I found the following resources handy:
https://learn.adafruit.com/ladyadas-lea ... n-number-0
http://docs.platformio.org/en/latest/wh ... ormio.html

Happy coding
Uten

User avatar
Uten
Posts: 129
Joined: Tue 29 Jan 2008, 11:00

arduino programing on puppy

#2 Post by Uten »

Taking a shot at the SerialCommand example I did stumble on a few hurdles to get it started. So a short writeup.

First get the code.

Code: Select all

// Demo Code for SerialCommand Library
// Steven Cogswell
// May 2011

#include <SerialCommand.h>

#define arduinoLED 13   // Arduino LED on board

SerialCommand sCmd;     // The demo SerialCommand object

void setup() {
  pinMode(arduinoLED, OUTPUT);      // Configure the onboard LED for output
  digitalWrite(arduinoLED, LOW);    // default to LED off

  Serial.begin(9600);

  // Setup callbacks for SerialCommand commands
  sCmd.addCommand("ON",    LED_on);          // Turns LED on
  sCmd.addCommand("OFF",   LED_off);         // Turns LED off
  sCmd.addCommand("HELLO", sayHello);        // Echos the string argument back
  sCmd.addCommand("P",     processCommand);  // Converts two arguments to integers and echos them back
  sCmd.setDefaultHandler(unrecognized);      // Handler for command that isn't matched  (says "What?")
  Serial.println("Ready");
}

void loop() {
  sCmd.readSerial();     // We don't do much, just process serial commands
}


void LED_on() {
  Serial.println("LED on");
  digitalWrite(arduinoLED, HIGH);
}

void LED_off() {
  Serial.println("LED off");
  digitalWrite(arduinoLED, LOW);
}

void sayHello() {
  char *arg;
  arg = sCmd.next();    // Get the next argument from the SerialCommand object buffer
  if (arg != NULL) {    // As long as it existed, take it
    Serial.print("Hello ");
    Serial.println(arg);
  }
  else {
    Serial.println("Hello, whoever you are");
  }
}


void processCommand() {
  int aNumber;
  char *arg;

  Serial.println("We're in processCommand");
  arg = sCmd.next();
  if (arg != NULL) {
    aNumber = atoi(arg);    // Converts a char string to an integer
    Serial.print("First argument was: ");
    Serial.println(aNumber);
  }
  else {
    Serial.println("No arguments");
  }

  arg = sCmd.next();
  if (arg != NULL) {
    aNumber = atol(arg);
    Serial.print("Second argument was: ");
    Serial.println(aNumber);
  }
  else {
    Serial.println("No second argument");
  }
}

// This gets set as the default handler, and gets called when no other command matches.
void unrecognized(const char *command) {
  Serial.println("What?");
}
I just copied it off the source and saved it in the same main.c file as I used for the blinky sample. If you do to and try to do a

Code: Select all

platformio run
you will probably end up with a lot off errors as I did.

First I thought the library SerialCommand was missing. So digging around a bit with

Code: Select all

platformio lib --help
platformio lib search
But it did not help. Then I came across some documentation indicating that I should add the library to the project file. That is in platformio.ini. So I did.

Code: Select all

lib_deps = SerialCommand
Do a search for lib_deps as there are several ways to specify a library (by number, version and so on).

At this point a

Code: Select all

platformio run
made platformio download and compile the SerialCommand library if I recall right. But Still I got a lot of errors. As the seasoned c/cpp programmer would expect the file extension is wrong. But changing it to cpp did not entierly fix it either.

Turns out there is another extension to be used in this domain. ino.

Code: Select all

mv src/main.c src/main.ino
did the trick.

So uploading it to the uno also worked. But if you have read the code the point of it is that you may send commands from your computer to your device and receive results. How do we set this up in a simple manner?

A terminal whit screen running is the ansver. A better soulution further down!
Open a terminal window and issue the command:

Code: Select all

screen /dev/ttyUSB0 9600
ttyUSB0 is where the code is uploaded to and 9600 is the baud-rate set in the code.

Now we split the window with
ctrl+a S. Move to the new split with Ctrl+a taband create a new terminal with Ctrl+a c

At this point we can send commands to our device in the last terminal we created. So try it out. First hit the reset button on your board. Then:

Code: Select all

echo -e ON > /dev/ttyUSB0
echo -e ON > /dev/ttyUSB0
echo -e OFF > /dev/ttyUSB0
echo -e HELLO > /dev/ttyUSB0
echo -e P 12 6 > /dev/ttyUSB0
I got this result back in the first screen window

Code: Select all

Ready
What?
LED on
LED off
Hello, whoever you are
We're in processCommand
First argument was: 12
Second argument was: 6
Now, this is way more fun than I thought it would be. So Now I have to get a Bluetooth breakout card for my UNO.

EDIT: Rather than using screen to monitor and a terminal to send it is better to use the incredible handy command:

Code: Select all

platformio device monitor 
Happy coding
Uten :D
Last edited by Uten on Wed 15 Mar 2017, 22:56, edited 1 time in total.

User avatar
Uten
Posts: 129
Joined: Tue 29 Jan 2008, 11:00

Arduino programming in Fatdog64

#3 Post by Uten »

This is just a collection of links to places I have found interesting or handy: This post will be edited from time to time.

The obligatory places
It is kind of obvious: https://www.arduino.cc/
The platformio tools: http://platformio.org/
Another framework: http://wiring.org.co/

Other sources
Some really good articles here: http://gammon.com.au/forum/bbshowpost.p ... pic_id=123
Ladyada, adafuit tutorials: https://learn.adafruit.com/series/learn-arduino
Multitasking ( a must read if your serious): https://learn.adafruit.com/multi-taskin ... ino-part-3
Some nice articles: https://folk.uio.no/jeanra/Microelectronics/

Forums and information:
http://forum.hobbycomponents.com
https://arduino-info.wikispaces.com
http://arduinolearning.com/

tools
A atmel avr simulator: http://www.nongnu.org/simulavr/
Front end gui tool: https://mydevices.com/cayenne/landing/arduino/

Libraries
EasySheduler, Not sure it's the right tool but I got it going: http://blog.protoneer.co.nz/arduino-task-scheduler/

Shopping parts
Aliexpress.com. By directly from China. Works better for me in Norway than buying from the states.Just search for what you need.
https://www.aliexpress.com/w/full retail plus shipping- ... oller.html
https://www.aliexpress.com/w/full retail plus shipping-arduino.html
Have not tried them, but they have some interesting boards: http://sensorembedded.com
Adafruit is obvious to some: https://www.adafruit.com/
modmypi:https://www.modmypi.com/shop
From UK: https://shop.pimoroni.com/

User avatar
Uten
Posts: 129
Joined: Tue 29 Jan 2008, 11:00

#4 Post by Uten »

I have made a communication sample with a gtkdialog gui. The code are found in this thread

User avatar
mister_electronico
Posts: 969
Joined: Sun 20 Jan 2008, 20:20
Location: Asturias_ España
Contact:

arduino

#5 Post by mister_electronico »

for 32 bits working in slacko 5.6.

http://www.murga-linux.com/puppy/viewto ... 467#876467


see you

Post Reply