Author Topic: Moteino and SPI  (Read 11796 times)

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5939
  • Country: us
    • LowPowerLab
Re: Moteino and SPI
« Reply #15 on: December 13, 2014, 10:40:50 PM »
Keep away from D9, it's the onboard LED.
moteino.com/#pinout
Wiznet is a module that I would also avoid, from experience - it will hang and the libraries are very heavy for the atmega328p.

scott216

  • Newbie
  • *
  • Posts: 41
Re: Moteino and SPI
« Reply #16 on: December 14, 2014, 06:16:50 AM »
Thanks for the feedback.  I didn't realize D9 was the LED.  What would you recommend for an Ethernet board?

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5939
  • Country: us
    • LowPowerLab
Re: Moteino and SPI
« Reply #17 on: December 15, 2014, 10:36:50 AM »
I think the WIZ library assumes CS=D10 but that's used by the RFM69 transceiver.
You can use any pin that is not used, please study the pinout to avoid confusion: moteino.com/#pinout

scott216

  • Newbie
  • *
  • Posts: 41
Re: Moteino and SPI
« Reply #18 on: December 15, 2014, 10:50:36 AM »
I think the WIZ library assumes CS=D10 but that's used by the RFM69 transceiver.
You can use any pin that is not used, please study the pinout to avoid confusion: moteino.com/#pinout

That's right, the Arduino Ethernet library does use D10, but I have some modified files that let you select a different CS pin:
See: http://forum.arduino.cc/index.php?topic=217423.msg1881620#msg1881620

scott216

  • Newbie
  • *
  • Posts: 41
Re: Moteino and SPI
« Reply #19 on: December 15, 2014, 05:20:23 PM »
Keep away from D9, it's the onboard LED.
moteino.com/#pinout
Wiznet is a module that I would also avoid, from experience - it will hang and the libraries are very heavy for the atmega328p.

I decided to upgrade my project and use the Moteino Mega (it arrived today).  Looking at the Moteino Mega PCB I see that CS is on pin 4, MOSI is pin 5, MISO pin 6 and SCK is pin 7.  Is that right?  On the regular Arduino MEGA the SPI pins are 51-53.  Will the standard Ethernet libraries work with the Moteino Mega and this SPI pin configuration?  Which Moteino Mega pin is used for CS for the radio module, is it pin 4?

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5939
  • Country: us
    • LowPowerLab
Re: Moteino and SPI
« Reply #20 on: December 15, 2014, 06:30:40 PM »

scott216

  • Newbie
  • *
  • Posts: 41
Re: Moteino and SPI
« Reply #21 on: December 16, 2014, 09:08:41 AM »
www.moteino.com/#pinoutMEGA

I just want to confirm - If I use the Arduino IDE and choose MoteinoMega (I haven't installed the Moteino Mega Core yet) for the board and use the standard Arduino Ethernet library, then the Moteino will use the MISO, MOSI and SCK pins as shown on the Moteino pinout for SPI communication.  I'm not worried about CS pin at this point.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5939
  • Country: us
    • LowPowerLab
Re: Moteino and SPI
« Reply #22 on: December 16, 2014, 09:57:22 AM »
That is library dependent not arduino variant/core dependent. You will have to check with the library.
The Motieno has the same pin assignments as the Arduino UNO. There is no arduino based on the atmega1284 so I don't know if the ethernet library will work with it.

scott216

  • Newbie
  • *
  • Posts: 41
Re: Moteino and SPI
« Reply #23 on: January 06, 2015, 07:35:29 AM »
That is library dependent not arduino variant/core dependent. You will have to check with the library.
The Motieno has the same pin assignments as the Arduino UNO. There is no arduino based on the atmega1284 so I don't know if the ethernet library will work with it.

I tried the MoteinoMega with my Ethernet shield and it worked fine.  I did use modified Ethernet libraries that let me change the slave select pin to something other than pin 10.

Here's the sketch I used.  It makes an API request to Weather Underground and then prints the wind speed to the serial monitor.
Code: [Select]
#include <SPI.h>
#include <Ethernet.h>     // modified to support alternate SS pin.  See http://bit.ly/1xNy2rP
#include <TextFinder.h>  // http://playground.arduino.cc/Code/TextFinder

// Slave Select Pins
const byte SS_PIN_ETHERNET = 12; 
const byte SS_PIN_MICROSD =  13; 
const byte SS_PIN_RADIO =    10; 

char server[] = "api.wunderground.com";   

byte g_mac[] = { 0xDE, 0xAD, 0xBD, 0xAA, 0xAB, 0xA5 };
byte g_ip[] = { 192, 168, 216, 40 }; 

EthernetClient client;

void setup()
{
  pinMode(SS_PIN_ETHERNET,    OUTPUT);
  pinMode(SS_PIN_RADIO,       OUTPUT);
  pinMode(SS_PIN_MICROSD,     OUTPUT);
 
  digitalWrite(SS_PIN_ETHERNET, HIGH);
  digitalWrite(SS_PIN_RADIO,    HIGH);
  digitalWrite(SS_PIN_MICROSD,  HIGH);
 
  Serial.begin(9600);
  delay(6000);
  Serial.println("MoteniMega Ethernet Test");
   
  // start the Ethernet connection:
  Ethernet.select(SS_PIN_ETHERNET);  // Set slave select pin - requires modified Ethernet.h library
  Ethernet.begin(g_mac, g_ip); 
  Serial.println(Ethernet.localIP());

  // give the Ethernet shield a second to initialize:
  delay(2000);
 
}


void loop()
{

  Serial.print(F("Wind speed: "));         
  Serial.print(getWind());
  Serial.println();         
  delay(10000);
 
}

byte getWind()
{
  TextFinder finder( client );
  float windDir = 0;

  if (client.connect(server, 80))
  {
    // Make a HTTP request:
    client.println(F("GET /api/cb0578a32efb0c50/conditions/q/pws:KVTWESTD3.json HTTP/1.1"));
    client.println(F("Host: api.wunderground.com"));
    client.println(F("Connection: close"));
    client.println();
  }
  else
  { Serial.println(F("connection failed"));  }

  if (client.connected())
  {
    if(finder.find("wind_mph"))
    {  windDir = finder.getFloat(','); }
  }
  else
  { Serial.println(F("not connected")); }
 
  client.stop();
 
  return windDir;
 
}

kiwisincebirth

  • Jr. Member
  • **
  • Posts: 69
Re: Moteino and SPI
« Reply #24 on: January 07, 2015, 06:34:09 AM »
Hi Scott, I am interested to know, have you gotten the W5100 ethernet and RFM69 working on a single Moteino. I am planning on trying to build a Gateway running on a single Moteino.

I have also been doing some SPI investigation, and there are software issues with multiple devices on the SPI bus, especially where interrupts are involved. This is described here

http://dorkbotpdx.org/blog/paul/spi_transactions_in_arduino

This new SPI capability has been released in Arduino 1.5.8 (not 1.0.6), and the ethernet libraries updated to support this. The RFM69 libraries have not had such attention.

scott216

  • Newbie
  • *
  • Posts: 41
Re: Moteino and SPI
« Reply #25 on: January 07, 2015, 06:54:47 AM »
Hi Scott, I am interested to know, have you gotten the W5100 ethernet and RFM69 working on a single Moteino. I am planning on trying to build a Gateway running on a single Moteino.

I have also been doing some SPI investigation, and there are software issues with multiple devices on the SPI bus, especially where interrupts are involved. This is described here

http://dorkbotpdx.org/blog/paul/spi_transactions_in_arduino

This new SPI capability has been released in Arduino 1.5.8 (not 1.0.6), and the ethernet libraries updated to support this. The RFM69 libraries have not had such attention.

Well, I wouldn't say me setup is super stable, it's okay though.  I do have my sketch reboot if it doesn't upload anything to weather underground for a while and I want to add a watch dog timer.  I'm using a modified Ethernet.h/cpp and w5100.h/cpp files which lets me  set the slave select pin to something other then D10.  This modification seems to work very well and I've used it on other projects.   All my code is posted on github here: https://github.com/Scott216/Weather_Station_Data.  You can also read about it on the associated GitHub Wiki page:

Modified libraries can be found here:
Arduino 1.0.5/6: http://forum.arduino.cc/index.php?topic=217423.msg1881620#msg1881620
Arduino 1.5.8:     http://forum.arduino.cc/index.php?topic=217423.msg1962182#msg1962182


TomWS

  • Hero Member
  • *****
  • Posts: 1888
Re: Moteino and SPI
« Reply #26 on: January 07, 2015, 08:54:09 AM »
@Scott216, can you tell us how much memory you're consuming with this application using the Ethernet library?

Kiwi and I are both interested, but I'm concerned about consuming all of RAM to support Ethernet on a AtMega328P.

Tom
By the way, I looked at the code, the TextFinder library looks pretty sweet for HTTP clients...

kiwisincebirth

  • Jr. Member
  • **
  • Posts: 69
Re: Moteino and SPI
« Reply #27 on: January 07, 2015, 06:26:48 PM »
Hi Tom

It is encouraging that the basic configuration does work. I myself am interested in MQTT communication over ethernet.

Compiling my Sketch with RFM69 Ethernet and the MQTT PubSubClient client, indicated 68% Flash consumed, and 66% SRAM consumed, this is with other stuff as well so there is some headroom

My investigation has shown that 1.5.8 has the new SPI libraries included, but also that the W5100 ethernet drivers have also been enhanced to use these features.

I am thinking that IF the new SPI library transaction support could be incorporated into the RFM69 library, then this might be the best outcome to deliver a stable solution.

Kiwi

TomWS

  • Hero Member
  • *****
  • Posts: 1888
Re: Moteino and SPI
« Reply #28 on: January 07, 2015, 06:45:02 PM »
Kiwi,
do you know if the two versions of IDE can peacefully coexist (ie, can I install the 1.5.8 version and it won't break my 1.5.7 setup)?

Seems like they could since everything is installed into a separate arduino-<version> folder, but I'd like to know that it will be ok before I install it.

Tom

scott216

  • Newbie
  • *
  • Posts: 41
Re: Moteino and SPI
« Reply #29 on: January 07, 2015, 07:24:05 PM »
@Scott216, can you tell us how much memory you're consuming with this application using the Ethernet library?

Kiwi and I are both interested, but I'm concerned about consuming all of RAM to support Ethernet on a AtMega328P.

Tom
By the way, I looked at the code, the TextFinder library looks pretty sweet for HTTP clients...

I'm compiling with IDE 1.0.5, but I want to try it with 1.5.8.  Compiling my sketch uses 29,780 bytes (of a 32,256 byte maximum).  At the end of my setup function, I get the free RAM which is 445 bytes. 

I did purchase a MoteinoMega and want to try that and see if it's more stable. 
« Last Edit: January 07, 2015, 07:27:43 PM by scott216 »