Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Mon 18 Dec 2017, 01:29
All times are UTC - 4
 Forum index » House Training » HOWTO ( Solutions )
Arduino programing in Fatdog64
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [3 Posts]  
Author Message
Uten


Joined: 29 Jan 2008
Posts: 109

PostPosted: Sun 05 Mar 2017, 14:04    Post subject:  Arduino programing in Fatdog64
Subject description: platformio and arduino uno
 

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..Surprised)

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:
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:
wget -qO- https://bootstrap.pypa.io/get-pip.py | python

Then we need to update setuptools
Code:
pip install setuptools

And then we get platformio
Code:
pip install -U platformio

To make platformio happy (it worked without, but) we get som udev rules
Code:
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:
command -v platformio

If it returns platformio the program is found and is executable.

Get a list of supported boards
Code:
platformio boards


Lets see if our board are found automatically
Code:

platformio device list


On my system the command returned:
Code:
/dev/ttyUSB0
------------
Hardware ID: USB VID:PID=1A86:7523 LOCATION=1-8.4
Description: USB2.0-Serial



Make a simple project
Code:
mkdir /tmp/test_project
cd /tmp/test_project
platformio init --board uno

Make the obligatory hello world blink application
Code:
geany src/main.c

And use something like
Code:

/**
 * 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:

platformio run

If we have success upload the code
Code:
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-learn-arduino-lesson-number-0
http://docs.platformio.org/en/latest/what-is-platformio.html

Happy coding
Uten
Back to top
View user's profile Send private message 
Uten


Joined: 29 Jan 2008
Posts: 109

PostPosted: Mon 06 Mar 2017, 10:07    Post subject:  arduino programing on puppy
Subject description: Get the SerialCommand example to work.
 

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:
// 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:
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:
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:
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:
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:
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:
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:
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:

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:
platformio device monitor


Happy coding
Uten Very Happy

Last edited by Uten on Wed 15 Mar 2017, 18:56; edited 1 time in total
Back to top
View user's profile Send private message 
Uten


Joined: 29 Jan 2008
Posts: 109

PostPosted: Tue 07 Mar 2017, 09:12    Post subject: Arduino programming in Fatdog64
Subject description: A collection of links
 

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.php?bbtopic_id=123
Ladyada, adafuit tutorials: https://learn.adafruit.com/series/learn-arduino
Multitasking ( a must read if your serious): https://learn.adafruit.com/multi-tasking-the-arduino-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-microcontroller.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/
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [3 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » House Training » HOWTO ( Solutions )
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1319s ][ Queries: 11 (0.0099s) ][ GZIP on ]