Archiv der Kategorie: Arduino

Do you like to have an Arduino KNX shield?

Some friends and I are currently thinking about designing and producing a first batch of Arduino KNX shields (including a matching Arduino library) as an update to the first development version.

First draft of Arduino KNX shield

First draft of Arduino KNX shield

If you are interested in getting an Arduino KNX shield, please sign up below (without any obligations). Based on the number of subscribers we will decide on how to proceed.

We won’t spam you. Period.

If you have any questions or suggestions please let us know by commenting on this post.

Update 12.01.2016: We just got the 100th subscriber on this list. This was our absolute minimum to pursue this project. Stay tuned for updates and thanks for your support.

Prototype PCBs of the Arduino TPUART Interface

Finally the first Arduino TPUART interface on a nice PCB is done:

After figuring out how to solder the surface-mounted TP-UART chip the rest was really easy and the Arduino is working with EIB / KNX as before. If you want to get some PCBs made for yourself, feel free to use this layout from the repository.

Connecting Arduino and Android wirelessly via WiFi using the RN-XV WiFly Module

The idea was to establish some kind of wireless connection between an Arduino (Mega in my case) and an Android phone (on 4.0 currently). The final idea is to remote control a quadrocopter using this link. Therefore there are some basic limitations – it should have a reasonable range and should not need any additional infrastructure (like Access Points or the like). The only options that come to mind is Bluetooth (probably a bit short in range) and WiFi; NFC can be excluded (only a few cm range). My first try was WiFi.

The RN-XV WiFly module is a comparatively cheap WiFi / WLAN module that can be used with Arduino. It connects to the Arduino using a serial link (UART).  Note, that it is powered with 3.3V and that it can take some power (according to the datasheet). Therefore it should be powered with a separate regulator as the one that is integrated on the Arduino board provides too less power (at least to specs, but I didn’t want to risk frying it). Besides that, one needs to bring the TTL level (5V) of Arduino down to 3.3V as well, which can be easily done using a voltage divider.

The schematics for hooking it up:

602a0a4b81

The RN-XV WiFly supports an AdHoc Mode (connect pin 8 to 3.3V). In this mode it creates an AdHoc network that you can easily connect to with a computer. Afterwards you can telnet to the module and configure it and to talk to the Arduino.

AdHoc-Mode sounded create for my use case and works really flawlessly with any computer. Unfortunately Android does not support joining AdHoc networks by default (there are some hacks that involve rooting the phone). Therefore this mode can’t be used here. Ok, so let’s try the other way round – open a HotSpot on your Android phone and let the RN-XV WiFly connect to it. This actually works really good. There’s one limitation here – you can’t open the HotSpot programmatically (not supported by the API). This means that users of your app would need to do that manually (which is not too big of a problem as this is DIY space anyway :-). So here’s how to do it.

First, open the HotSpot on your phone choosing an SSID and a password. Also, you might want to disable that the HotSpot switches itself off if there’s no activity for a certain amount of time. On my HTC One X it looks like this:

4134b8aacb

Second, configure the RN-XV WiFly module. Do this by putting the module in AdHoc Mode (connect pin 8 to 3.3V) and connect a computer to the network. Then, telnet to 169.254.1.1, port 2000. I used these commands for configuration:

$$$     // Enter command mode

set sys printlvl 0     // Disables debug output
set uart baud 115200     // Set baudrate on UART interface to Arduino
set wlan auth 3
set wlan phrase YOURPASSPHRASE
set wlan ssid YOURSSID
set wlan rate 8      // 6 Mbit/s - according to docs lowering the data rate increases range
save
reboot

Third, put a test program to the Arduino. I used the MultiSerial example from the Arduino site, slightly modified:

void setup() {
  // initialize both serial ports:
  Serial.begin(115200);
  Serial3.begin(115200);
}

void loop() {
  // read from port 1, send to port 0:
  if (Serial3.available()) {
    int inByte = Serial3.read();
    Serial.write(inByte);
  }

  // read from port 0, send to port 1:
  if (Serial.available()) {
    int inByte = Serial.read();
    Serial3.write(inByte);
  }
}

Fourth, test the connection with your computer. Open the serial monitor from the Arduino IDE alongside your telnet connection to the module (still running in AdHoc). You should be able to type something in the telnet session and see it on the serial monitor and vice versa.

Last but not least we need an Android app. I will not go into the details of creating an Android app here (Google provides good docs on it). Here’s the source code for connecting a socket to the first (and hopefully the only) client of your HotSpot and send some chars to it.

InetAddress in;
try {
 List<ClientScanResult> clients = getClientList(true, 500);
 for (ClientScanResult client : clients) {
  Log.d(TAG, "Found client " + client.getHWAddr() + " " + client.getDevice() + " " + client.getIpAddr());
 }

 in = InetAddress.getByName(clients.get(0).getIpAddr());
 if (in.isReachable(500)) {
  Log.d(TAG, "Arduino reachable");
  socket = new Socket(in, 2000);
  for (int i = 0; i < 7; i++) {
   // Read *HELLO*
   socket.getInputStream().read();
  }
 } else {
  Log.d(TAG, "Arduino not reachable");
 }
} catch (UnknownHostException e) {
 Log.e(TAG, "Could not connect: " + e.getMessage(), e);
} catch (IOException e) {
 Log.e(TAG, "Could not connect: " + e.getMessage(), e);
}

Note that the getClientList() method (called in line 3) and the ClientScanResult class is from Whitebyte. Thanks for this!

And that’s it. You now have a wireless connection between Arduino and Android that you can use just like a serial link.

Connecting an Arduino to EIB/KNX

Update 14.07.2015: We are currently thinking about producing an Arduino KNX shield. Please let us know if you are interested. Thanks!

After having heard about it a couple of times already, I recently rediscovered the Arduino for myself and quickly came up with an idea for a first project – connecting it to KNX (formerly known as EIB). This was actually quite easy and I’d like to share my experience (and code) here in case somebody wants to do a similar thing.

To interface with KNX an interface IC is required (at least if you’re not able to build one on your own). I used a Siemens TP-UART for the job (obtained from Opternus Components). The TP-UART converts the signal from KNX to a UART signal (compatible with Arduino’s serial ports) and cares for a lot of the low-level details, e.g. line access control and telegram repetition. The serial protocol is described in depth in the TP-UART datasheet.

To connect the TP-UART to KNX you need some rather standard parts (resistors, capacitors, diodes, a crystal, …). To a large extend I used a schematic designed by the TU of Vienna for their TP-UART PC Interface Board. On the Arduino side I added optocouplers to isolate from KNX. The full schematic is as follows (you can find the Eagle files in the Bitbucket repository):

b4165158c9

I built it up on a breadboard for now using an Arduino Mega 2560. Using the Mega is the simplest solution as it has multiple UARTs so that you can connect the usual USB for programming and the TP-UART at the same time. This makes debugging using the serial “console” easy.

IMG_5613

Next, I needed some software. After fiddling around with the Arduino IDE for a short time, I noticed it’s pretty limited (at least if you’re used to full-fledged environments like Eclipse). So I quickly started building a library in Eclipse. The library has a comparably simple interface to the user such that he/she doesn’t have to care about the details of the KNX / TP-UART protocol. While implementing the library I needed some time to figure out the details of the protocol (e.g. when I need to send the ACK / NACK confirmation on an incoming telegram). Overall however it was not too difficult.

The whole source code of the library can be found on my Bitbucket repository for this project. There are also some examples in there that show the use of the library. The first “real” example is the use of a Dallas temperature sensor and sending its values to KNX in regular intervals and also answering to read requests on a certain group address – in the repository the “TemperatureReadoutOneWire” example.

Feel free to use the library for anything you want (of course without any warranty). If you have any improvements, suggestions or found a bug please let me know e.g. by using the issue tracker.