Source Code Beautifier

Posted on Updated on

I found that the other day and love it. It helps to nicely display code or whatever in blog posts.

Link

Enjoy.

Advertisements

Arduino: collect2.exe: error: ld returned 5 exit status

Posted on

I spent hours to try to find a solution to fix this error at compilation.

My code don’t have any problem, just the things showed up after upgrading arduino (win XP).

What I did at the end was to add dummy variable to the code and it worked. Try to add 1, 2, 3 , 4 and it worked!!

Example:

byte y1 = 0; byte y2 =0; byte y3 =0; byte y4=0;

good luck!

Pinball

Posted on Updated on

A project that I have started few months ago.

Basically, everything is working. Using Pinball fx2 for the games.

Link to vector artwork

Link to 3D of cabinet

Link to control

Time to keep up with the project… It has been sleeping forĀ  while.

What’s coming next:

Backglass with DMD and screen for image. Nudge control with accelerometer (basic setting). A bit of lighting…

DMD: Setting of Pin2Dmd.

I use a STM32F4 discovery board, P4 1/16 led matrix (cheaper than P2.5). I spent about a day to make this working; I could not get the board working with the last firmware (2.42). The communication with the PC was not responding. I then downgraded to 2.38 and all was fine excepted an image not sharp (kind of glitching or ghosting). I found out that I needed a bit more of 3.3 V to control the P4 because of the bus-driver of the P4, 74HC245, the HC version requires more than the HCT version. This is something that I will add on shield board for final connection. I decreased the supply of the P4 of few mV (final supply 4.7V).

Everything works fine now. I just need to register to get a key from PIN2DMD.

pin2dmd

Next, a bit of light show for the backglass. To make the thing simple, I tested something like Ambilight. It extends the sides color of the screen to led stripes. Simple and okay to make some animation. For testing, I used the software AMBIBOX (direct download) and the following arduino code (need FastLED Library)

#include "FastLED.h"
#define NUM_LEDS 24
#define DATA_PIN 3
#define serialRate 115200
static const uint8_t prefix[] = {'A', 'd', 'a'};

// Define the array of leds
CRGB leds[NUM_LEDS];

void setup() {
  FastLED.addLeds<WS2811, DATA_PIN, RBG>(leds, NUM_LEDS);
  Serial.begin(serialRate);
  Serial.print("Ada\n");
}

void loop() {
  for (int i = 0; i < sizeof(prefix); ++i) {
    while (!Serial.available());
    if (prefix[i] != Serial.read())
      return;
  }
  while (Serial.available() < 3);
  int highByte = Serial.read();
  int lowByte  = Serial.read();
  int checksum = Serial.read();
  if (checksum != (highByte ^ lowByte ^ 0x55)) {
    return;
  }

  uint16_t ledCount = ((highByte & 0x00FF) << 8 | (lowByte & 0x00FF) ) + 1;
  if (ledCount > NUM_LEDS) {
    ledCount = NUM_LEDS;
  }

  for (int i = 0; i < ledCount; i++) {
    while (Serial.available() < 3);
    leds[i].r = Serial.read();
    leds[i].g = Serial.read();
    leds[i].b = Serial.read();
  }
  FastLED.show();
}

 

Nudge control:

I use my previous Arduino due arcade control and added a bit of code for the accelerometer (ADXL345) reading. It is in testing now not 100% okay.

#include 

#include 
#include 
#include 

//change debounce time to 1ms
//will add led control

#define DEBOUNCE 1                                                      // how many ms to debounce

//define the buttons that we'll use.
byte buttons[] = {22, 23, 24, 25, 26, 27, 28, 29};
byte out[] = {44, 45};
byte key[] = {129, 133, 176, 218, 217, 216, 215, 177};                  //left shift, right shift, return, Up Arrow, Down Arrow, Left Arrow, Right Arrow, Esc


//128 left ctrl
//132 right ctrl
//32 space


// need to add up down left right esc

//determine how big the array up above is, by checking the size
#define NUMBUTTONS sizeof(buttons)
#define NUMOUTS sizeof(out)

//track if a button is just pressed, just released, or 'currently pressed'
byte pressed[NUMBUTTONS], justpressed[NUMBUTTONS], justreleased[NUMBUTTONS];
byte previous_keystate[NUMBUTTONS], current_keystate[NUMBUTTONS];
float x_before;
float y_before;
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);

void setup() {
  byte i;

  /* Initialize the sensor */
  if (!accel.begin())
  {
    while (1);
  }


  Keyboard.begin();

  for (i = 0; i < NUMBUTTONS; i++) {
    pinMode(buttons[i], INPUT);

    digitalWrite(buttons[i], HIGH);

  }

  for (i = 0; i < NUMOUTS; i++) {
    pinMode(out[i], OUTPUT);
    digitalWrite(out[i], LOW);

  }

  accel.setRange(ADXL345_RANGE_2_G);
  accel.setDataRate(ADXL345_DATARATE_3200_HZ);

  sensors_event_t event;
  accel.getEvent(&event);

  x_before = event.acceleration.x;
  y_before = event.acceleration.y;


}

void loop() {

  float x_now, y_now;
  sensors_event_t event;
  accel.getEvent(&event);
  x_now = x_before - event.acceleration.x;
  y_now = y_before - event.acceleration.y;
  if (abs(x_now) > abs(y_now)) {

    if ((x_now) > 1.5) {

      Keyboard.press(32);
      delay(50);
      Keyboard.release(32);
    }
  } else
  {

    if ((y_now) > 2) {
      Keyboard.press(128);
      delay(50);
      Keyboard.release(128);
    }
    if ((y_now) < -2) {
      Keyboard.press(132);
      delay(50);
      Keyboard.release(132);
    }
  }

  check_switches();

  for (byte i = 0; i < NUMBUTTONS; i++) {

    if (justpressed[i]) {

      Keyboard.press(key[i]);

    }

    if (justreleased[i]) {

      Keyboard.release(key[i]);
    }

  }
}

void check_switches()
{
  static byte previousstate[NUMBUTTONS];
  static byte currentstate[NUMBUTTONS];
  static long lasttime;
  byte index;
  if (millis() < lasttime) {
    // we wrapped around, lets just try again
    lasttime = millis();
  }
  if ((lasttime + DEBOUNCE) > millis()) {
    // not enough time has passed to debounce
    return;
  }
  // ok we have waited DEBOUNCE milliseconds, lets reset the timer
  lasttime = millis();
  for (index = 0; index < NUMBUTTONS; index++) {
    justpressed[index] = 0; //when we start, we clear out the "just" indicators
    justreleased[index] = 0;
    currentstate[index] = digitalRead(buttons[index]); //read the button

    if (currentstate[index] == previousstate[index]) {
      if ((pressed[index] == LOW) && (currentstate[index] == LOW)) {
        // just pressed
        justpressed[index] = 1;
      }
      else if ((pressed[index] == HIGH) && (currentstate[index] == HIGH)) {
        justreleased[index] = 1; // just released
      }
      pressed[index] = !currentstate[index]; //remember, digital HIGH means NOT pressed
    }
    previousstate[index] = currentstate[index]; //keep a running tally of the buttons
  }
}

 

Backglass work in progress.

Install Node-Red in Win10

Posted on Updated on

  • Install node.js – I am using version 5.4.0. Download

Once installed in command window

npm install -g --unsafe-perm node-red

then install dashboard

npm install node-red-dashboard

 

Done

Flow – Set Date and Time

Posted on Updated on

I needed for a user interface using dashboard to change the system date and time for only offline use.

Set time zone using raspi-config to UTC

and then:

[{"id":"36c3d555.2f131a","type":"ui_form","z":"95a3d4b7.c328c","name":"","label":"Time Setting","group":"d5789dec.c52058","order":0,"width":0,"height":0,"options":[{"label":"Fri Nov 4 17:50:00 UTC 2016","value":"Time","type":"text","required":true}],"formValue":{"Time":""},"payload":"","topic":"","x":116.5,"y":66,"wires":[["a31c7a2b.05a228"]]},{"id":"b1edd921.e154a","type":"exec","z":"95a3d4b7.c328c","command":"sudo date","addpay":true,"append":"","useSpawn":"","timer":"","name":"Set Time","x":431.5,"y":64.5,"wires":[["23954dbb.e1b912"],[],[]]},{"id":"d0531b60.f27f88","type":"ui_text","z":"95a3d4b7.c328c","group":"d5789dec.c52058","order":0,"width":"0","height":"0","name":"","label":"Actual System Date and Time","format":"{{msg.payload}}","layout":"row-spread","x":505.5,"y":157,"wires":[]},{"id":"9f79c87.21b00b8","type":"inject","z":"95a3d4b7.c328c","name":"","topic":"","payload":"","payloadType":"date","repeat":"1","crontab":"","once":true,"x":122.5,"y":153,"wires":[["5f3c74a9.0f72bc"]]},{"id":"23954dbb.e1b912","type":"debug","z":"95a3d4b7.c328c","name":"","active":true,"console":"false","complete":"false","x":608.5,"y":64,"wires":[]},{"id":"5f3c74a9.0f72bc","type":"function","z":"95a3d4b7.c328c","name":"","func":"// Create a Date object from the payload\nvar date = new Date(msg.payload);\n// Change the payload to be a formatted Date string\nmsg.payload = date.toString();\n// Return the message so it can be sent on\nreturn msg;","outputs":1,"noerr":0,"x":278.5,"y":156,"wires":[["d0531b60.f27f88"]]},{"id":"e2689290.c72908","type":"function","z":"95a3d4b7.c328c","name":"","func":"msg.payload = \"-\" +'\"' + \"s \" + msg.payload + '\"';\nreturn msg;\n\n//sudo date -\"s Fri Nov 4 17:50:00 UTC 2016\"","outputs":1,"noerr":0,"x":274.5,"y":273,"wires":[["26012639.277dea"]]},{"id":"adb62291.b5d0c8","type":"inject","z":"95a3d4b7.c328c","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":126.5,"y":273,"wires":[["e2689290.c72908"]]},{"id":"26012639.277dea","type":"debug","z":"95a3d4b7.c328c","name":"","active":true,"console":"false","complete":"false","x":458.5,"y":274,"wires":[]},{"id":"a31c7a2b.05a228","type":"function","z":"95a3d4b7.c328c","name":"","func":"var strtime = msg.payload.Time;\nmsg.payload = \"-\" +'\"' + \"s \" + strtime + '\"';\nreturn msg;","outputs":1,"noerr":0,"x":276,"y":65,"wires":[["26012639.277dea","b1edd921.e154a"]]},{"id":"d5789dec.c52058","type":"ui_group","z":"","name":"Time Setting","tab":"862d2fe5.7ba4a","order":1,"disp":false,"width":"16"},{"id":"862d2fe5.7ba4a","type":"ui_tab","z":"","name":"Setting","icon":"dashboard","order":2}]

Flow – Send command

Posted on Updated on

A couple of commands example.

 [{"id":"9d317c9d.94ec4","type":"inject","z":"95dd8c1e.9f45b8","name":"shutdown!","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":254,"y":105,"wires":[["47b1920.62f3bf"]]},{"id":"47b1920.62f3bf","type":"exec","z":"95dd8c1e.9f45b8","command":"sudo poweroff #","append":"","useSpawn":"","name":"turn off Pi","x":428,"y":104,"wires":[[],[],[]]},{"id":"28150e2f.21a1ea","type":"inject","z":"95dd8c1e.9f45b8","name":"reboot!","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":255,"y":188,"wires":[["f211e72e.571f78"]]},{"id":"f211e72e.571f78","type":"exec","z":"95dd8c1e.9f45b8","command":"sudo reboot #","addpay":false,"append":"","useSpawn":"","timer":"","name":"Reboot Pi","x":430,"y":193,"wires":[[],[],[]]},{"id":"9fdf1eef.cd09f","type":"inject","z":"95dd8c1e.9f45b8","name":"video off","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":248,"y":277,"wires":[["d5a598dc.db0b9"]]},{"id":"d5a598dc.db0b9","type":"exec","z":"95dd8c1e.9f45b8","command":"vcgencmd display_power 0","addpay":false,"append":"","useSpawn":"","timer":"","name":"Video Off","x":431,"y":279,"wires":[[],[],[]]}]

screen-shot-2016-11-05-at-7-21-04-am

Flow – Dashboard Reset Chart

Posted on Updated on

If you like to reset the content of a graph in Node-Red dashboard, use this method.

[{"id":"69c51240.a88d64","type":"ui_chart","z":"95dd8c1e.9f45b8","name":"","group":"982d5ce1.fdf228","order":4,"width":"5","height":"2","label":"","chartType":"line","legend":"false","xformat":"%H:%M","interpolate":"linear","nodata":"","ymin":"-40","ymax":"80","removeOlder":1,"removeOlderUnit":"3600","x":521,"y":119,"wires":[[],[]]},{"id":"9475826e.ef16e","type":"json","z":"95dd8c1e.9f45b8","name":"","x":348.5,"y":121,"wires":[["69c51240.a88d64"]]},{"id":"72de27fd.a64e08","type":"inject","z":"95dd8c1e.9f45b8","name":"Reset","topic":"","payload":"[ { \"key\": \"Data\", \"values\": []}]","payloadType":"str","repeat":"","crontab":"","once":false,"x":185.5,"y":121,"wires":[["9475826e.ef16e"]]},{"id":"982d5ce1.fdf228","type":"ui_group","name":"Group 1","tab":"6db0468b.7fc248","order":1,"disp":true,"width":6},{"id":"6db0468b.7fc248","type":"ui_tab","z":"","name":"Test","icon":"dashboard","order":3}]

screen-shot-2016-11-04-at-11-34-54-pm