Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

WiFly Shield


  • Please log in to reply
64 replies to this topic

#1 Genious

Genious

    Member

  • Members
  • PipPip
  • 10 posts

Posted 21 October 2010 - 11:52 AM

Hi, this is my first post, so please be kind! I have been trying to get my Netduino to talk to a Sparkfun WiFly shield. I've been basing my code on the Arduino example on the Sparkfun website (the autoconnect example here: http://www.sparkfun....utorials_id=158). The Arduino code compiles, runs and works straight out of the box. However, my port to the Netduino doesn't. I manage to write a character out to the SPI/UART chip and get a response back as expected, so I assume my SPI connection is working (had to alter a baud rate setting to do this, as the shild I have has a different crystal). When I issue commands to the WiFly module via the SPI/UART chip the serial activity light flashes. However, the commands I send seem to be completely ignored! According to the WiFly manual and the example, sending "$$$" should enter command mode and the module should reply with "CMD". This doesn't happen though. I attempt to read characters back after sending "$$$" and get nothing. Is there some difference with reading and writing to the Netduino SPI port compared to the Arduino? I noticed that when I want to read a byte over SPI, I need to send the "read" command twice and get the return value in the second byte of the SPI data I get back. How is this handled with the Netduino's SPI? When is it safe to ignore the values returned on writes to the SPI port? Is there any documentation for SPI on Netduino? Also, has anyone managed to get this module working before? Many thanks! PS: Will post code when I get home!

#2 Genious

Genious

    Member

  • Members
  • PipPip
  • 10 posts

Posted 21 October 2010 - 06:56 PM

Code as promised... getting desperate now!

using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;

namespace WirelessTester
{
    public class Program
    {
        private static SPI _spi;

        private const byte LCR = 0x03 << 3;
        private const byte DLL = 0x00 << 3;
        private const byte DLM = 0x01 << 3;
        private const byte EFR = 0x02 << 3;
        private const byte FCR = 0x02 << 3;
        private const byte SPR = 0x07 << 3;
        private const byte RHR = 0x00 << 3;
        private const byte LSR = 0x05 << 3;
        private const byte THR = 0x00 << 3;
        private const byte DivL = 0x60;//0x50;
        private const byte DivM = 0x00;
        private const byte DataFormat = 0x03;
        private const byte Flow = 0x10;

        public static void Main()
        {
            // write your code here
            OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);

            SPI.Configuration config = new SPI.Configuration(
                Pins.GPIO_PIN_D10,
                false,
                0,
                0,
                false,
                true,
                10000,
                SPI.SPI_module.SPI1);

            _spi = new SPI(config);

            Thread.Sleep(1000);

            _spi.Write(new byte[] { LCR, 0x80 });
            _spi.Write(new byte[] { DLL, DivL });
            _spi.Write(new byte[] { DLM, DivM });

            _spi.Write(new byte[] { LCR, 0xBF });
            _spi.Write(new byte[] { EFR, Flow });
            _spi.Write(new byte[] { LCR, DataFormat });
            _spi.Write(new byte[] { FCR, 0x06 });
            _spi.Write(new byte[] { FCR, 0x01 });

            SpiUartWriteChar('H');

            char c = (char) SpiUartReadByte(SPR);

            Debug.Print(c.ToString());

            //SpiUartWriteLine("");
            //SpiUartWriteLine("exit");
            //Thread.Sleep(500);

            SpiUartFlush();
            SpiUartWrite("$$$");
            Debug.Print(SpiUartReadLine());
            Thread.Sleep(500);
            led.Write(true);
            SpiUartWriteLine("reboot");
            Thread.Sleep(3000);
            led.Write(false);

            SpiUartWrite("$$$");
            Debug.Print(SpiUartReadLine());
            Thread.Sleep(500);

            SpiUartWriteLine("set w a 3");
            Debug.Print(SpiUartReadLine());
            Thread.Sleep(500);

            SpiUartWriteLine("set w p sdgvsfdsf");
            Debug.Print(SpiUartReadLine());
            Thread.Sleep(500);

            SpiUartWriteLine("set i l 80");
            Debug.Print(SpiUartReadLine());
            Thread.Sleep(500);

            Thread.Sleep(100);
            SpiUartFlush();
            Thread.Sleep(100);
            SpiUartWriteLine("join ManParadise");
            Thread.Sleep(10000);
            Debug.Print(SpiUartReadLine());

            SpiUartWriteLine("show c");

            Debug.Print("Setup done");

            while(true)
            {
                string s = SpiUartReadLine();
                if (s != "") Debug.Print(s);
            }
        }

        private static void SpiUartFlush()
        {
            int i = 0;
            while (i < 1000)
            {
                if ((SpiUartReadByte(LSR) & 0x01) == 0x01)
                {
                    SpiUartReadByte(RHR);
                }
                else
                {
                    i++;
                }
            }
        }

        private static string SpiUartReadLine()
        {
            int i = 0;
            string data = "";
            while(i < 1000)
            {
                if ((SpiUartReadByte(LSR) & 0x01) == 0x01)
                {
                    byte b = SpiUartReadByte(RHR);

                    //if (b == '\n' || b == 0xFF)
                       // break;

                    data += (char)b;
                }
                else
                {
                    i++;
                }
            }

            return data;
        }

        private static void SpiUartWriteLine(string data_)
        {
            SpiUartWrite(data_ + "\n");
        }

        private static void SpiUartWrite(string data_)
        {
            Debug.Print(data_);

            byte[] sendBuffer = new byte[data_.Length];
            for (int i = 0; i < data_.Length; ++i)
            {
                sendBuffer[i] = (byte) data_[i];
            }

            _spi.Write(new byte[] {THR, 0x01});

            _spi.Write(sendBuffer);

        }

        private static void SpiUartWriteChar(char c_)
        {
            _spi.Write(new[] { SPR, (byte)c_ });
        }

        private static byte SpiUartReadByte(byte addr_)
        {
            byte[] b = new byte[2];
            _spi.WriteRead(new byte[] { (byte) (addr_ | 0x80) }, B);
            return b[1]; 
        }
    }
}


#3 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 21 October 2010 - 10:24 PM

Has anyone else here played with the WiFly shield yet on their Netduino? I'm not sure if we ihave one here, but we could certainly get one in... For SPI, as long as the WiFly shield can accept 3.3V data signals you should be good to go. BTW, what clock speed is SPI using for the WiFly on the Arduino? 10MHz? Chris

#4 James

James

    Advanced Member

  • Members
  • PipPipPip
  • 56 posts

Posted 22 October 2010 - 05:10 PM

This shield looks ideal for my purposes - they're out of stock now but I'll definitely buy one when available. Looking forward to seeing the progress on this thread!

#5 Genious

Genious

    Member

  • Members
  • PipPip
  • 10 posts

Posted 24 October 2010 - 05:22 PM

I've worked on this for a few more hours and still not had any success.

* I know the SPI/Serial chip is outputting something because the activity light flashes.
* I know that the WiFly shield itself works because it works with my Arduino.
* I know that whatever activity I'm sending isn't working, because I can't get the chip to work!

I'm totally at a loss now really... I really want to make the shield work, but I just don't know what else to try. The current solution looks like I'll have to use the Arduino to act as a serial/WiFly bridge - a solution that takes up too much space, too much power and looks nasty!

Any help you guys can give would be massively appreciated.

Dan

#6 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 26 October 2010 - 09:10 AM

Hi Dan, We're trying to buy one of these, but can't find any in stock. Do you know where we can get one that's the same model as yours? Chris

#7 Genious

Genious

    Member

  • Members
  • PipPip
  • 10 posts

Posted 26 October 2010 - 06:08 PM

Hi Chris, I'm in the UK. I got mine from... http://www.coolcompo...products_id=456 It means a lot that you're looking into this for me - many thanks and good luck finding a shield somewhere. I do think that the netduino and wifly is a great combination and I'm sure there'll be lots of other people interested in using them together when (if!) there's a driver. Cheers, Dan

#8 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 26 October 2010 - 07:47 PM

Okay, we found one. Should arrive within in a week (or two max)... Chris

#9 James

James

    Advanced Member

  • Members
  • PipPipPip
  • 56 posts

Posted 04 November 2010 - 10:39 PM

Contacted Sparkfun about availability and they think they'll have more shields ready in a week or two. Looking forward to getting this stuff running!

#10 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 05 November 2010 - 01:07 AM

Contacted Sparkfun about availability and they think they'll have more shields ready in a week or two. Looking forward to getting this stuff running!


That's great news. We just got ours. Now to solder it together :) Then the fun/hard work begins...

Chris

#11 Genious

Genious

    Member

  • Members
  • PipPip
  • 10 posts

Posted 08 November 2010 - 04:01 PM

Any luck so far? ;) Dan

#12 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 08 November 2010 - 06:03 PM

Any luck so far? ;)


For better or worse, it's going to be _quite_ the project. We're just starting to play with it. I'll post an update when we see first light on it...

Chris

#13 Mustang

Mustang

    Member

  • Members
  • PipPip
  • 26 posts
  • LocationDetroit, Michigan

Posted 19 November 2010 - 03:50 PM

I am getting an error in the SpiUartReadByte function. VS2010 Ultimate seems to think that B does not exist in the current Context. I think I am going to start from scratch and see what I can come up with. I'll post here if i make any progress. I seem to have some issues. I've not used a "shield" before. Should I have any LEDs lit? I see nothing, and when Ia m using SPI.WriteRead(byte[], byte[]), It's returning all 255's (using a 64bit buffer for the moment, just to see if I can send ANY data, and receive it back). I guess my question is, How can I just test functionality of the board? I am using the sparkfun stackable headers to connect it to the netduino. It's not a snug fit, and I think I might have connection issues. It just seems like nothing is happening. After further testing, I am getting NO response from the wifly shield at all. I'll have to get a meter on it and see what's going on. Might be a bad board. Is there just a way to test only the state without reading UART? I only want to know IF it's functional and no one I know has an Arduino.

#14 Maurice Spronkers

Maurice Spronkers

    New Member

  • Members
  • Pip
  • 9 posts
  • LocationRozenburg (ZH), The Netherlands

Posted 22 November 2010 - 09:26 AM

For better or worse, it's going to be _quite_ the project. We're just starting to play with it. I'll post an update when we see first light on it...

Chris



Any update on this shield? Are the lights on?

Thanks,
Maurice Spronkers

#15 James

James

    Advanced Member

  • Members
  • PipPipPip
  • 56 posts

Posted 22 November 2010 - 05:25 PM

It looks like these are back in stock at SparkFun: http://www.sparkfun.com/products/9954 Would it be safe to order one and know that it'll work with Netduino at some point?

#16 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 22 November 2010 - 05:28 PM

Would it be safe to order one and know that it'll work with Netduino at some point?


We're at the "early experimental" phase right now. We'd love to support it. Working on it...

Chris

#17 Maurice Spronkers

Maurice Spronkers

    New Member

  • Members
  • Pip
  • 9 posts
  • LocationRozenburg (ZH), The Netherlands

Posted 24 November 2010 - 07:52 AM

Okee, thats good news. Got mine shield yesterday. Now waiting for the driver to play with it. Kind regards, Maurice Spronkers

#18 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 25 November 2010 - 11:09 PM

Genious, Mustang...

First, a word on the WiFly shield itself...

Power Requirements
The WiFly shield has its own power regulator (instead of using the 3.3V power regulator built into the Netduino). This may be due to the higher power requirements of the WiFly module (to prevent overloading the 3.3V power regulator on the Arduino).

The shield's power regulator feeds power off of the VIN line instead of the 5V pin. So this means that you need to provide external power to the Netduino when using this shield (or if you're up for modifying the shield, there are a number of options there too...removing the power regulator, current forwarding diodes, etc. etc.). A 7.5V-12V AC-DC power adapter, 9V battery, etc. should all work nicely.

SPI-to-UART bridge
Basically, there is a SPI-to-UART chip on the shield which converts SPI-based data to serial UART data...which is then sent to the WiFly module itself. If you hooked up a WiFly module to the Netduino itself directly (instead of through the shield), you could just use UART 2 (pins 2/3 with RTS/CTS)...but for the sake of compatibility we'll work with the SPI-to-UART bridge.

Driver
We've had some very preliminary success getting data to/from the WiFly module on the shield. There are a number of pieces to be built to create a good driver: SPI-to-UART bridge code, setup code, configuration code, communication code, etc.

From a performance standpoint, the best networking solution will be to use a Netduino Plus with a WiFi-to-Ethernet bridge. But let's see what we can do with WiFly (or the ZeroG module used on the AsyncLabs WiFi shields)...it would be awesome to build out a WiFi solution.

Chris

#19 Innovactive

Innovactive

    Member

  • Members
  • PipPip
  • 29 posts

Posted 26 November 2010 - 07:03 AM

Hi. We finally succeeded in using a WiFly Shield in a real world Netduino app. What we did is actually a little battery powered box embedding a Netduino, a WiFly shield and a Devantech SRF-05 Sonar. One of more of such boxes, placed inside a secured perimeter, act as "fences" that raise events via TCP whenever they're "hit" (our sonar has a range of about 3m). TCP server that receives notifications is hosted by an Internet provider, and uses such notifications to "push" (via Silverlight Full Duplex Binding support) UI updates to web clients, that, after about 1 sec, show an icon flashing. Such icon is tipically overlayed to a building plant diagram that shows where exactly the fence has been violated. We'll post details about this project very soon.

#20 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 26 November 2010 - 07:11 AM

Very cool, Innovactive! We'd love to see what you've built. Perhaps we could even feature it on the projects page for a while (if you wanted to share...and it came with instructions, diagrams, etc.)? Chris




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.