Digital Inputs being blocked?

Postings related to the second version of the WiShield

Digital Inputs being blocked?

Postby franklovecchio » Tue Aug 17, 2010 7:26 pm

Not to light up your forum Greg, but I'm sure this is a basic hardware concept I'm missing. With no WiShield, this sketch reports back an input based on a pulse. With the WiShield, it reports back nothing (and therefore doesn't post!).

No WiShield code:
Code: Select all
int inputPin = 2; // choose the input pin (for a pushbutton)
int val = 0; // variable for reading the pin status
int prevState = 0;

void setup() {
pinMode(inputPin, INPUT); // declare pushbutton as input
Serial.begin(9600);
}

void loop(){
pinMode(inputPin, INPUT);           // set pin to input
digitalWrite(inputPin, HIGH);       // turn on pullup resistors
prevState = val;
val = digitalRead(inputPin); // read input value
if (val != prevState) {
  if (val == HIGH) { // check if the input is HIGH
    Serial.print("Gallon");
    Serial.print("");
  } else {
  }
}
}



WiShield code:
Code: Select all

#include <WiShield.h>
#define WIRELESS_MODE_INFRA   1
#define WIRELESS_MODE_ADHOC   2

// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,10,xx};   // IP address of WiShield
unsigned char gateway_ip[] = {192,168,10,1};   // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0};   // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"asfasdfads"};      // max 32 bytes

unsigned char security_type = 3;   // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2

const prog_char security_passphrase[] PROGMEM = {"asfadsasdf"};   // max 64 characters

prog_uchar wep_keys[] PROGMEM = {   0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,   // Key 0
                           0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   0x00,   // Key 1
                           0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   0x00,   // Key 2
                           0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   0x00   // Key 3
                        };

unsigned char wireless_mode = WIRELESS_MODE_INFRA;

unsigned char ssid_len;
unsigned char security_passphrase_len;
//---------------------------------------------------------------------------

int inputPin = 5; // choose the input pin (for a pushbutton)
int val = 0; // variable for reading the pin status
int prevState = 0;

void setup() {
  pinMode(inputPin, INPUT); // declare pushbutton as input
  Serial.begin(9600);
  WiFi.init();
}

unsigned char loop_cnt = 0;

char ip[] = {xxx,xx,225,182};
const prog_char twitter[] PROGMEM = {"POST /xxxxx HTTP/1.1\r\nUser-Agent: uIP/1.0\r\nHost: xxxx\r\nContent-Length: 6\r\nContent-Type: application/x-www-form-urlencoded\r\n\r\nGallon"};

void loop() {
  pinMode(inputPin, INPUT);           // set pin to input
  digitalWrite(inputPin, HIGH);       // turn on pullup resistors
  prevState = val;
  val = digitalRead(inputPin); // read input value
  if (val != prevState) {
    if (val == HIGH) { // check if the input is HIGH
      webclient_get(ip, 80, "/");
      Serial.print("Gallon");
    } else {
    }
  } 
 
  WiFi.run();   
}
franklovecchio
 
Posts: 9
Joined: Wed Aug 04, 2010 5:14 pm

Re: Digital Inputs being blocked?

Postby GregEigsti » Tue Aug 17, 2010 8:08 pm

Not to light up your forum Greg

Its not my forum - I just find the WiShield intriguing and have some experience writing network code. I want to see AsyncLabs succeed and this is one little thing that I can do to give them a hand.

The issue is not immediately obvious to me - it looks like it should work... :lol:

I'd start debugging this by slowly removing/commenting networking code until something becomes apparent. So a few questions I would seek to answer are:
  • Does the original, working, example still work if you switch it to pin 5 as well?
  • Do the first two lines of your loop() function really need to be there (I'm sure this is not related but I'm wondering if they even need to be there)
  • What happens if you swap the order of webclient_get() and Serial.print() (or just comment out webclient_get()) - do you get the serial output of "Gallon" then?
Just basic troubleshooting steps done one at a time, then tested, to see where things are going off of the hook.

Edit - this is interesting to me as a learning experience so I'm going to try to look at it on real hardware. Was going to look at it last night but got interested in the multiple UDP port issue thread (and it did not require connecting a switch/wires) ;)

Greg
Check out the wiki!
uIP Stack Docs
Compatible Access Point List
WiShield user contrib branch - DNS, DHCP, AP Scanning, bug fixes, etc.
SlackLab.org - My geek projects blog.
User avatar
GregEigsti
 
Posts: 1067
Joined: Sun Aug 02, 2009 5:23 pm
Location: Sammamish WA USA (near Seattle)
  • Website

Re: Digital Inputs being blocked?

Postby spidermonkey04 » Fri Aug 20, 2010 8:44 pm

Not to light up your forum Greg
Ha, I got a kick outta that. Greg, you do so much work around here, people are starting to think you own the place :D

I see you're using digital pin 2 as the push button. Are you then using dig8 as the WiShield interrupt pin? ( set in spi.h )

Greg is right, you don't need pinMode() in the loop, unless you're switching it to OUTPUT somewhere else.

---Jared
spidermonkey04
 
Posts: 66
Joined: Thu Oct 29, 2009 6:45 pm

Re: Digital Inputs being blocked?

Postby GregEigsti » Fri Aug 20, 2010 11:20 pm

Ha, I got a kick outta that. Greg, you do so much work around here, people are starting to think you own the place :D

Didn't you hear? I'm the new owner and you owe me $0.25 for your last post :twisted:

Frank is using pin 2 in his non WiShield code and pin 5 in his WiShield code - one of my questions was about the proper operation of pin 5 in the non WiShield code.

TGIF!!!
Greg
Check out the wiki!
uIP Stack Docs
Compatible Access Point List
WiShield user contrib branch - DNS, DHCP, AP Scanning, bug fixes, etc.
SlackLab.org - My geek projects blog.
User avatar
GregEigsti
 
Posts: 1067
Joined: Sun Aug 02, 2009 5:23 pm
Location: Sammamish WA USA (near Seattle)
  • Website


Return to WiShield 2.0

Who is online

Users browsing this forum: No registered users and 1 guest