0

Recently, I've been writing an Arduino(Yún) sketch to get RGB values(0-255) from the bridge. I have Bridge.begin() in the setup and the following in the loop:

Bridge.get("r", r, 4);
Bridge.get("g", g, 4);
Bridge.get("b", b, 4);

Which should get the value from the bridge(1st argument) and set the local variable to it(2nd argument). The local variables r, g and b are defined with char r[4];(obviously each with the appropriate name). I understand all of this, however there is a problem:

The first Bridge.get() call always returns \u0001(Start of heading). I have solved this by adding a dummy bridge get to the beginning of the loop, however this seems weird to me because the first call returns the "Start of heading" in every loop.

Why is this and is there a better way to fix it?

EDIT:

The code is put to the bridge by a python script running on the Linux side of the Yún. The following is shortened because the code that works out the RGB values is fairly long, messy and shouldn't be part of the problem(famous last words :D).

#!/usr/bin/python
from sys import path
path.insert(0, '/usr/lib/python2.7/bridge')
from bridgeclient import BridgeClient
link = BridgeClient()
link.put("r", str(int(r)))
link.put("g", str(int(g)))
link.put("b", str(int(b)))

The arduino code(once again abridged) is as follows:

#include <Process.h>
char r[4];
char g[4];
char b[4];

void setup() {
  Bridge.begin();
}

void loop() {
  Process colo;
  colo.runShellCommand("/mnt/sda1/colours.py");
  while (colo.running());
  Bridge.get("r", r, 4); //this command(whatever key it’s getting) always returns \u0001
  Bridge.get("r", r, 4);
  Bridge.get("g", g, 4);
  Bridge.get("b", b, 4);
}
Tugzrida
  • 491
  • 2
  • 6
  • 17
  • How are you calling Bridge.put()? – John Davis Jan 03 '16 at 01:44
  • From a python script on the Linux side. I can't just have it pass the values back; I need them in the bridge as they're used for other things too. The only part I don't understand is why the first `Bridge.get()` returns that character every time the loop runs. – Tugzrida Jan 03 '16 at 02:42
  • Any chance you could post complete code? – John Davis Jan 03 '16 at 13:25
  • Just a thought - have you tried putting a delay(10) at the end of the loop? I am wondering if the serial connection does not have enough time to init and that is causing the issue. Give it a shot and let know if that works. If not, I will do some testing on my end. – John Davis Jan 05 '16 at 21:14
  • Well, it would seem that I can no longer recreate this problem! Even if I get rid of the delay I had in there already then it works fine. I don't even know how this is possible because I haven't changed anything on the Yún side. The only possible explanation is that the Yún libraries on my laptop(and therefore the ones uploaded to the Yún) are a newer version than before. Anyway, thanks for your help! – Tugzrida Jan 16 '16 at 06:12
  • Although I have added a 200ms delay just to keep it working well; with no delay it was flaky but working without the dummy `Bridge.get`. – Tugzrida Jan 16 '16 at 06:31
  • Well, at least it is working! Glad to hear. – John Davis Jan 18 '16 at 11:49

0 Answers0