Brand New Intel Edison

Just got my new Intel Edison in the mail the other day, I convinced myself to order it to “Investigate” it for a project I am working on, but in reality I just wanted an excuse to buy one (Keep reading I actually bought 2).

 

To get started I just looked it up on the internet.

Above is the video I used to get started.  During the first night I ended up running the wrong linux commands causing my entire OS to get messed up (*note to self: make sure to run rm only on the specific directories you want to run it on, not everything)  This eventually messed up the Edison and I was unable to do anything with the Edison.  Using the instructions on this post (https://communities.intel.com/thread/58226) I was able to re install the OS and get the Edison working again.


Because I did not feel like dealing with switching the 1.8V logic to 3.3V or 5V logic I decided to pick up the arduino breakout board (This being my second Intel Edison).

To test out some basic functionality I hooked up a range finder sensor. I used some code from one of my other projects to get it going.  The code is very generic and can be found all over the internet if you are curious of how to use a range sensor.  (With the code below “Wire.h” should be apparently I cannot figure out how to make it not delete automatically)

#include "Wire.h"
#define trigPin A1
#define echoPin A0

void setup() {
  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}

void loop() {

  get_distance(trigPin, echoPin);

  Serial.println(" cm");
  delay(300);

}

void get_distance (int trig, int echo)
{
  long duration, distance;
  digitalWrite(trig, LOW);  
  delayMicroseconds(2); 
  digitalWrite(trig, HIGH);
  delayMicroseconds(10); 
  digitalWrite(trig, LOW);
  duration = pulseIn(echo, HIGH);
  distance = (duration/2) / 29.1;

  if (distance >= 500 || distance <= 0){
    Serial.print("Out of range ");
  } 
  else {
    Serial.print(distance);
  }
  Serial.print(" - ");
  delayMicroseconds(200);
}


I wanted to make sure that I could control the pins from python as well.  So After some research I found this library called Wiring-x86 (http://wiring-x86.readthedocs.org/getting_started.html)

To make my life easier, I just installed nano with “wget http://www.nano-editor.org/dist/v2.2/nano-2.2.6.tar.gz && tar xvf nano-2.2.6.tar.gz && cd nano-2.2.6 && ./configure && make && make install” – https://communities.intel.com/thread/55602

Just using the base code from https://github.com/emutex/wiring-x86/tree/master and the code worked fine.  This allowed me to control the LED on pin 13.

To double check all of this, I went to use the Blink example code set provided with the arduino IDE, I had issues at first loading the code, but after I reset the board It worked like a champ.  I am going to investigate why the board didn’t work on the first try with the arduino code, but I have a feeling it may be related to the wiring-x86 library I was using.  But I cannot say for certain yet.

Despite this being a new board to work with, there is a lot of information on the internet about it and how to use it, and the forums seem to be a good place for issues that you run into.

 

My  plan for these guys is to use it on my RC car project that I have been stalling on for over 2 years now.  But I am going to tackle that another day.

 

 

More Reading:

 

http://blog.dimitridiakopoulos.com/2014/09/10/hands-on-intel-edison/

http://jamidwyer.com/blog/node/35

http://fab-lab.eu/edison/

 

 

Beginning with the Parallax Propeller

It has been a while, a long while, but here is what I am working on tonight.

I recently picked up a Parallax Propeller.  After installing the software from the Parallax page I started to just mess around in code.  I am programming it in C.  With this being a multicore board the whole point is to use more than one core.

So before today I had never programmed anything using more than one thread.  So I had to do some research, found pthreads.h and went to work.  I also apparently forgot some basics about pointers, starting 8 threads all using the same pointer does exactly like it sounds like it does, the value is the same in all of them.  I tried setting the values of a variable and passing that in as a pointer to the creation of the thread, then change the value of the data in the memory and create another thread (and repeat a couple more times).  All I wanted to do was turn on all the lights on the board and then turn them off, what I got was all the lights turning on and the last one flickering.

After some careful thought I realized I made a rookie mistake, I used the same memory to store the  different values to pass into all the threads.  So I turned up with something that looked like this to make it better.

#include "simpletools.h"
#include <pthread.h>

typedef struct
{
  int light;
  int sleep;
} do_toggle_input;

void *do_toggle(void *argv)
{
  pthread_set_affinity_thiscog_np();
  do_toggle_input* vars = (do_toggle_input*)argv;
  printf("%d,%d\n",vars->light,vars->sleep);
  while(1)
  {
    high(vars->light);
    usleep(1000000);
    low(vars->light);
    usleep(1000000);
  }
}

void main (int argc,  char* argv[])
{
  pthread_t thr;
  do_toggle_input vars;
  void* var_ptr = &vars;
  usleep(200000);
  vars.sleep = 10000;
  vars.light = 16;
  var_ptr = &vars;
  printf("%d\n",vars.light);
  pthread_create(&thr, NULL, do_toggle, var_ptr);
  int i;
  for(i=16;i<24;i++)
  {
    vars.light = i;
    usleep(2000010);
    if(i==23)
    {
      i=15;
    }
  }
}

All this code does is turn on and off each light on the board, except if you notice the time is off, so it eventually switches over to all being on, and one being turned off and on.

One last thing to note, the struct that I use, I was using the sleep variable initially, but decided to hard code it.