Go Down

Topic: Arduino Yun using WiFi and DMX Shield (Timer problem?) (Read 577 times) previous topic - next topic

chaosspirit

Hello community,

I am stuck at a problem which is kind of way out of my league. Following setup:

I have an Arduino Yun, a DMX-Shield (CTC-DRA-10-R2) and use DmxSimple library.
Yun receives via WiFi a string from Unity. This string contains a number von 0 to 100 and is converted to an integer. This integer serves as a value for a DMX channel.

The shield has a jumper for EN (enabled) and NOT EN (disabled) position. As the shield uses the Arduino serial, it has to be disabled when uploading sketches. (See Manual) As long as the shield is disabled I can use the serial monitor and see, that Unity sends values (via Debug.Log in Unity console window) and that Yun receives those values (via Serial.print() in serial monitor).

Here comes my problem:
When I enable the DMX-Shield and start my Unity script I get an error that the socket has been refused by the server and since the DMX-Shield is enabled (thus serial is blocked) I can not check for Yuns' status in the serial monitor.

Thoughts
From my point of understanding, blocking the serial connection should not interfere with the Tcp Connection over WiFi with Unity, as it worked when the serial was not blocked. After some use of Google I stumbled upon this post. Something about an issue concerning "...multiple definition of '__vector_25'...", changing a timer2 to timer4 and a suggestion from a user called "francois". After a while I found this suggestion (huge pile of code in the middle of the page), only to be confused if this is the right approach to my problem.

Questions
1. Is there a way to check my Yuns' serial monitor while the DMX-Shield is enabled?

2. Am I on the right track to solve my problem by changing timer2 to timer4?
   if (Yes)
      Serial.print("How do I change timer2 to timer4?");

3. Is there a DMX library which is sure to work? ( I tried DmxMaster and DmxSimple. Not to mention Conceptinetics, which don't seem to even work corretly with Arduino IDE)

with kind regards
Sebastian


PS: Here my Yun sketch:
Code: [Select]
#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>
#define PORT 255

#include <DmxSimple.h>


YunServer server(PORT);
YunClient client;

static boolean clientActive = false;
String saveString;
int value;

void setup()
{
  Bridge.begin();
  server.noListenOnLocalhost();
  server.begin();
  client = server.accept();

  DmxSimple.usePin(3);
  DmxSimple.maxChannel(1);
}

void loop ()
{
  client = server.accept();
  if (!clientActive)
    Serial.println("New client connection.");
  clientActive = true;
  if(client.available() > 0)
  {
    Serial.print("From client: \"");
    saveString = client.readStringUntil(10); // 10 entspricht dem ASCII-Wert des Line Feed im Byte
    value = saveString.toInt();
    Serial.println(value);
    Serial.println("\"");
    client.flush();
    DmxSimple.write(1, value);
  }
}


PPS: If my Unity script has any chance of being at fault here:
Code: [Select]
using UnityEngine;
using System;
using UnityEngine.UI;
using System.Net.Sockets;
using System.Collections;
using System.IO;

public class Network_Script : MonoBehaviour {

public Slider slider;
public Text sliderText;
int value;

internal Boolean socketReady = false;
TcpClient mySocket;
NetworkStream theStream;
StreamWriter theWriter;
StreamReader theReader;
String Host = "192.168.43.41";
Int32 Port = 255;


void Start(){
SetupSocket ();
}

void Update(){
value = (int)slider.value;
sliderText.text = value.ToString();
WriteSocket (value.ToString());
}

public void SetupSocket(){
try{
mySocket = new TcpClient(Host, Port);
theStream = mySocket.GetStream();
theWriter = new StreamWriter(theStream);
theReader = new StreamReader(theStream);
socketReady = true;
}
catch (Exception e){
Debug.Log ("Socket error: " + e);
}
}

public void WriteSocket(string theLine){
if (!socketReady)
return;
String foo = theLine + "\r\n";
theWriter.Write (foo);
theWriter.Flush ();
}

/*public String ReadSocket(){
if (!socketReady)
return "";
try {
return theReader.ReadLine ();
} catch (Exception e) {
Debug.Log ("Error ReadSocket: " + e);
return "";
}
}*/

public void CloseSocket(){
if (!socketReady)
return;
theWriter.Close ();
theReader.Close ();
mySocket.Close ();
socketReady = false;
}
}

DarkSabre

Only in answer to #1, but you may have better luck if you:
- #include <Console.h>
- change your Serial.println commands to Console.println
- connect to the Yun over the network (ethernet or wifi)
- you will get to the Console instead of the Serial Monitor
- as long as the Bridge still works while the DMX is enabled, you should be able to get feedback from the sketch through the Console

I'm afraid I'm quite unfamiliar with the other issues.

ShapeShifter

I can't immediately find a schematic for the shield, but from the descriptions I did find, it does not look like the shield is compatible with the Yun. It appears that the shield uses the serial port on pins 0 and 1 for communications and control. On most Arduino boards, those are the pins used to talk to your computer and the serial monitor. That's why you must disable the shield's serial connection to load sketches, and the re-enable it to use the shield - the shield's rx/tx lines interfere with the standard USB connection to a computer.

The Yun is different: it uses a dedicated USB interface to talk to the computer, so the shield should not conflict with that in any way - you should not have to disable anything on the shield to use the serial monitor or upload sketches. That's good news, but you have a much bigger problem: on the Yun, pins 0 and 1 are used for communications between the Linux processor and the AVR processor running the sketch. The shield's use of those pins conflicts with this.

The Bridge library in general, and the YunServer/YunClient in particular, absolutely need exclusive use of the serial port on pins 0 and 1 - that's how the network connection between the sketch and the rest of the world is established. The link is managed by the Linux side, and the data is passed between Linux and the sketch using the serial port.

You say that you think blocking the serial connection should not interfere with the TCP connection. In reality, it does interfere.

chaosspirit

The DMX shield I'm using I bought at DFRobot. There is a link to the shields schematics on Arduino Playground (here).

@ShapeShifter
If I understand you correctly, I should be able to upload my sketches on Yun while the DMX shield is enabled. But there is no communication possible between the linux core, which handles WiFi, and the 32u4, as they use pin 0 and 1 to communicate which is blocked by the DMX shield.

That means I can not controll the DMX output wirelessly, but should still be able to run a sketch with hardcoded values for my Dmx output from the arduino core side of my Yun.
So I went ahead and put a little sketch together, which includes LED on pin 13 to check for its' behaviour.
But another issue appeared. While running, the LED would light up and down as intended but the connected DMX fan did not react at all. (JEM AF-1 MKII)
So I checked a few things:

1. Which values does the fan accept?
In the manual it says, that values between 0 and 255 equal an output strength of 0% to 100%. I made sure, that the values in the sketch toggle between 0 and 255 with a reasonable delay.

2. Is the shield enabled and is there voltage on the dmx plug?
Yes and Yes (3.9V)

I tried using both DmxSimple and DmxMaster libraries and the fan was set to slave mode. Nothing.
Has this issue still to do with the conflict on pins 0 and 1 between Yun and the Dmx shield, which I haven't fully grasped yet?


Sketch
Code: [Select]
#include <DmxSimple.h>
#include <Bridge.h>

int windStrength;
boolean boo;

void setup() {
  DmxSimple.usePin(3);
  DmxSimple.maxChannel(16);
  digitalWrite(13, LOW);
  digitalWrite(13, HIGH);
  delay(1000);
  digitalWrite(13, LOW);
}

void loop() {
  digitalWrite(13, HIGH);
  delay(100);
  digitalWrite (13, LOW);

  if (boo){
    windStrength = 0;
    boo = false;
  } else {
    windStrength = 255;
    boo = true;
  }
  DmxSimple.write(1, windStrength);
  delay(15000);
}


with kind regards
Sebastian


Sidenote: Is it possible to enable and disable the shield and the WiFi communication to create a cycle, which looks for data on the network, disables the connection and enables the DMX shield to send the current value to the fan?

ShapeShifter

The DMX shield I'm using I bought at DFRobot. There is a link to the shields schematics on Arduino Playground (here).
The DFRobot page doesn't have a schematic (at least not one that jumps off the page at me) and the schematic on the Playground isn't particularly useful here because it doesn't show the shield connections that are the real question.

Quote
If I understand you correctly, I should be able to upload my sketches on Yun while the DMX shield is enabled. But there is no communication possible between the linux core, which handles WiFi, and the 32u4, as they use pin 0 and 1 to communicate which is blocked by the DMX shield.
Correct.

Quote
That means I can not controll the DMX output wirelessly, but should still be able to run a sketch with hardcoded values for my Dmx output from the arduino core side of my Yun.
Not correct. I didn't say that, you heard what you wanted to hear. I said you should be able to upload a sketch, I never said that the sketch would be able to control the shield.

The shield will simply not work if it uses pins 0 and 1 to communicate to the Yun. With the shield connected, the AVR processor's serial transmit line will be connected to the receiver of both the shield and the Linux processor. When the sketch sends data to the shield, it will be transmitting to both the shield and the Linux processor - the shield will understand the command, but the Linux processor will not. In the other direction, the transmitters from the shield and the Linux processor will both be connected to the receiver of the AVR processor. These two outputs will be fighting each other, and the result is that no useful data will pass through - everything will be garbled. When you send something, the shield will respond, but the Linux processor will also respond with an error message because it doesn't understand the DMX command. Those two responses will interfere resulting in an unintelligible mess.

Quote
Sidenote: Is it possible to enable and disable the shield and the WiFi communication to create a cycle, which looks for data on the network, disables the connection and enables the DMX shield to send the current value to the fan?
No. This isn't a software problem, it's a basic hardware problem: you cannot have two outputs (the shield Tx and Linux Tx) connected to a single input (the AVR processor Rx.)

The DFRobot page makes mention of jumpers to use pins 4 and 5 for control instead of pins 0 and 1. You will have to figure out how to make pins 4 and 5 work. The intent is probably to use SoftwareSerial on pins 4 and 5. The problem is that the '32U4 processor on the Yun (same processor as on the Leonardo) cannot use pins 4 or 5 for software serial reception.

The simple answer is that this DMX shield is not compatible with the Yun. It's probably possible to make it work, but it will require some clever hardware hacking and software modifications - probably not a beginner project.

Go Up