Show Posts
Pages: [1] 2 3
1  Using Arduino / Programming Questions / Re: Reading someone else's code, PWM and strange low-level code shenanigans! on: December 30, 2013, 02:58:47 pm
This is for some sort of IR remote control?

The first code segment looks like it sets up timer 2 to output a 38kHz (typical for IIRC) out of the associated PWM pin.

The second code segment looks like it turns the timer On (output 38kHz signal) and Off (output nothing) for time periods that are also typical of IRRC, by setting or clearing bits in the timer control register.  So instead of turning the pin on and off, it's outputting 38kHz or not...

For exact explanations, you'll have to refer to the datasheet.  For instance, the "v = 8000/38" line implies (to me) that it's expecting to run on an 8MHz board (8000 kHz = 8MHz), but there could be other factors involved.


Yes it is for IRRC. So essentially what you're saying is that timer 2 is controlling pin 3's PWM by pulsing it at 38khz for a time interval, then turning it off for a time interval, etc.? Why couldn't something like this be able to be done with a simple analogwrite()?
2  Using Arduino / Programming Questions / Reading someone else's code, PWM and strange low-level code shenanigans! on: December 29, 2013, 11:39:19 pm
So I'm doing some research in preparation for a new project and I found some relevant code to help. I'm a bit confused however about some syntax used in the code that looks pretty low-level. It starts with this in the setup():
Code:
// Setup PWM: f=38Khz PWM=0.5  
  byte v = 8000 / 38;
  TCCR2A = _BV(WGM20);
  TCCR2B = _BV(WGM22) | _BV(CS20);
  OCR2A = v;
  OCR2B = v / 2;
What? Then later an LED attached to pin 3 needs to be flashed and to do so, the code looks a little something like this:
Code:
// "Header" sequence
void sendHeader() {

  TCCR2A |= _BV(COM2B1);
  delayMicroseconds(HEADER_DURATION);
  TCCR2A &= ~_BV(COM2B1);
  delayMicroseconds(HEADER_DURATION);
  TCCR2A |= _BV(COM2B1);
  delayMicroseconds(HIGH_DURATION);
  TCCR2A &= ~_BV(COM2B1);

}
It seems to be that TCCR2A |= _BV(COM2B1); is the same as digitally writing pin 3 HIGH and TCCR2A &= ~_BV(COM2B1); writes it low. But what the heck is this? Some alternative way to reference pins that can get around some weird PWM frequency or duty cycle restrictions? What's up with those bitwise operators? Anybody that could help decode and explain this for me would be of great help.
3  Using Arduino / Project Guidance / Re: Is it Feasible to Make an E-Field Proximity Sensor With Arduino? on: September 24, 2013, 01:50:35 pm
Basically, you are talking about capacitive sensing.

Awesome, thanks.
4  Using Arduino / Project Guidance / Is it Feasible to Make an E-Field Proximity Sensor With Arduino? on: September 23, 2013, 09:55:26 pm
Inspired by the theremin and a general interest in proximity sensing, I was wondering if it would be possible to employ the use of an electromagnetic field and a microcontroller to detect when the field is disrupted by some conducting material (Like a person's skin). I've built an EMF detector with Arduino before, so I'm thinking I can use the same methods to detect the field I will create. However, I'm not entirely sure yet how to create and sustain the field (Perhaps inductors?), and I'm not sure how large/strong I need to make the field in order for some conductive material moving through it to make a significant enough change in the field to be detected by the Arduino. Any help is appreciated, thanks.
5  Using Arduino / Project Guidance / Re: Is it possible for an iPhone to read serial data from an Arduino? on: February 17, 2013, 06:11:14 pm
Great, thanks.
6  Using Arduino / Project Guidance / Re: Is it possible for an iPhone to read serial data from an Arduino? on: February 17, 2013, 05:56:51 pm
Yes an iPhone can receive serial data but you have to register as a developer to write any code on an iPhone. Then the only way you can get this code onto the iPhone is to submit it to Apple and have them put it in the Apps store.
Actually you don't even have to submit it to the app store, you can deploy the app straight to your iPhone/iPod if you're registered as a developer. You can write code for the device without being registered as a developer too, you just need to register to get it on the device. But you're sure an iPhone can receive serial data and code can be written to handle it?
7  Using Arduino / Project Guidance / Is it possible for an iPhone to read serial data from an Arduino? on: February 17, 2013, 05:30:21 pm
If I had a TTL serial converter cable such as the Redpark (http://www.makershed.com/Redpark_TTL_Cable_for_iOS_p/msrp03.htm), is it possible to send serial data to the iPhone from the Arduino and then have the iPhone respond? I've seen people use the cable to transmit data from the iPhone to the Arduino, but not yet the other way around. My purpose for this is to make a breathalyzer apparatus that you simply connect to you phone through something like the Redpark cable, load the app, and blow into the breathalyzer to get feedback on your phone regarding your BAC. If it's impossible for the iPhone to receive data like that over serial due to a software restriction or something, does anybody have any other suggestions? I'm trying to avoid internet connectivity for the sake of ease and simplicity to use.
8  Using Arduino / Networking, Protocols, and Devices / Re: Unable to connect to web server, can't seem to find the problem on: February 13, 2013, 10:42:23 pm
Never mind, I've fixed it. Turns out my router was reset with an ethernet connection already established on one of its ethernet ports and it screwed up the whole system. Just had to unplug and plug back in.
9  Using Arduino / Networking, Protocols, and Devices / Re: Unable to connect to web server, can't seem to find the problem on: February 12, 2013, 11:11:13 pm
Is this ip in the subnet of your localnet?
Code:
byte ip[] = { 10, 0, 1, 8 };
Are you using the port with it in your web browser?
http://10.0.1.8:8010

edit: Eye Korretd mi spelin misteak.  smiley-wink

Yes and yes

Quote
These two statements:
Code:
  pinMode(A3, INPUT);
and
Code:
  int val = analogRead(A3);    //read pot analog input
do not go together.

Analog pins are input only. They can not be set to output, nor do they have pullup resistors. So, the pinMode() command is completely unaware that they exist. You are diddling with the digital nature of that pin, which you don''t use. So, don't diddle with it.
Right, that was my bad. But how would this have an effect on my problem?
10  Using Arduino / Networking, Protocols, and Devices / [Solved] Unable to connect to web server, can't seem to find the problem on: February 11, 2013, 09:42:33 pm
I want to adjust the background color of a web page by adjusting a pot, but I can't for the life of me figure out why I'm not able to connect to the web server. I just get "Unable to connect to server" in my browser. Here's the code, help point me towards anything missing or that needs revision please.

Code:

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x50, 0x9A };
byte ip[] = { 10, 0, 1, 8 };

EthernetServer server(8010);

void setup() {

  pinMode(A3, INPUT);
  
  Serial.begin(9600);
  
  Ethernet.begin(mac, ip);
  server.begin();

}

void loop() {
  
  EthernetClient client = server.available();
  
  int val = analogRead(A3);    //read pot analog input
  
  if (client) {
    
    boolean current_line_is_blank = true;
  
    while (client.connected()) {
    
      if (client.available()) {
        
        char c = client.read();
        int color = map(val, 0, 1023, 0x000000, 0xFFFFFF);    //map the analogRead() values to HEX values for HTML colors
        
        Serial.println(val);    //print em'
        Serial.println(color);
        Serial.println();
        
        if (c == '\n' && current_line_is_blank) {
        
          client.println("HTTP/1.1 200 OK");    //standard HTTP header, a little HTML too
          client.println("Content-Type: text/html");
          client.println();
          client.println("<html><head><title>");
          client.println("Change pot to change color!");
          client.println("</title><body bgcolor=");
          client.print(color);
          client.println(">");
          client.println("<h1>Hello, World</h1>");
          client.println();
          client.print("</body></html>");
        
        }
        
        if (c == '\n') {
        
          current_line_is_blank = true;
        
        } else if (c != '\r') {
        
          current_line_is_blank = false;
        
        }
      
      }
    
    }
    
    delay(1);
    client.stop();
  
  }

}
11  Using Arduino / Networking, Protocols, and Devices / Controlling LED With Web Server Buttons on: February 02, 2013, 01:18:30 pm
Having trouble getting this to function correctly. I have an Arduino with an Ethernet Shield hosting a web server that has two buttons controlling the high or low state of an LED. The page loads fine with the "On" button and the "Off" button using POST, but whenever I press either they don't work. Here's my code, anyone happen see the problem?

Code:

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x50, 0x9A };
byte ip[] = { 10,0,1,8 };

const int MAX_PAGENAME_LEN = 8;   //Max number of characters for page name
char buffer[MAX_PAGENAME_LEN+1];   //Max number of characters + terminating null is the buffer

EthernetServer server(8010);

void setup() {

  Serial.begin(9600);
  
  Ethernet.begin(mac, ip);
  server.begin();

  delay(2000);
  
}

void loop() {

  EthernetClient client = server.available();
  
  if (client) {
  
    int type = 0;
    
    while (client.connected()) {
    
      if (client.available()) {
      
        memset(buffer, 0, sizeof(buffer));  //clear the buffer
        if (client.find("/")) {
        
          if (client.readBytesUntil('/', buffer, sizeof(buffer))) {
          
            Serial.println(buffer);
            if (strcmp(buffer, "POST ") == 0) {  //find the start of the posted form
            
              client.find("\n\r");  //skip to the body
              
              while(client.findUntil("pinD", "\n\r")) {  //find string starting with "pin", stop on first blank line
              
                int pin = client.parseInt();   //the number after "pinD" is the pin number
                int val = client.parseInt();   //the number after the pin number is its value (1 or 0)
                pinMode(pin, OUTPUT);
                digitalWrite(pin, val);
              
              }
            
            }
            
            sendHeader(client, "Post example");   //send a standard header, set up both buttons with POST
            client.println("<h2>Press button to control LED</h2>");
            client.print("<form action='/' method='POST'><p><input type='hidden' name='pinD8'");
            client.println(" value='1'><input type='submit' value='On'/></form>");
            client.print("<form action='/' method='POST'><p><input type='hidden' name='pinD8'");
            client.println(" value='0'><input type='submit' value='Off'/></form>");
            client.println("</body></html>");
            client.stop();
          
          }
          
          break;
        
        }
      
      }
      
      delay(1);
      client.stop();
    
    }
  
  }
  
}  

void sendHeader(EthernetClient client, char *title) {   //standard HTTP header

  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println();
  client.print("<html><head><title>");
  client.print(title);
  client.println("</title><body>");

}
12  Using Arduino / Networking, Protocols, and Devices / Re: Arduino Ethernet Web Server With Airport Extreme on: January 13, 2013, 10:16:51 pm
Quote
do I set the private IP as the Arduino's private IP or the Airport's?
Forward to the Arduino's private IP.

Quote
And then once I map it will other people be able to use my public IP on the port I forwarded to access the web server?
That's the theory.

-br


I believe my problem is this. Every time I go to forward a port, I forward it to the Arduino's IP. However then the Airport must restart to apply this change. When this happens, the Arduino is given a new IP. The cycle continues forever?
13  Using Arduino / Networking, Protocols, and Devices / Arduino Ethernet Web Server With Airport Extreme on: January 13, 2013, 08:01:00 pm
I need some help pertaining to setting up a web server for an Arduino with Ethernet Shield from an Apple Airport Extreme so that it will be available to the world. I have the Arduino connected by an RJ45 LAN cable to an ethernet port on the Airport, and my sketches are working, but only locally. I can't seem to figure out the process from this point on. When I map the ports from the Airport, do I set the private IP as the Arduino's private IP or the Airport's? And then once I map it will other people be able to use my public IP on the port I forwarded to access the web server?
14  Using Arduino / Installation & Troubleshooting / Re: Arduino Uno R3 Communication Problem on: January 13, 2013, 01:17:02 pm
This is exactly what happened to me once. It's nothing wrong with your USB Serial chip. Unfortunately I can not completely recall what I did to fix it, but I'm almost positive it was just pushing the ATMega chip back into proper place. If that isn't the problem (and you are completely sure), check to make sure the USB connecter is firmly connected to the USB port on your computer and the port on your Arduino. Also check if the "ON" light is green when you connect the USB cable.
15  Using Arduino / Networking, Protocols, and Devices / Re: Arduino Ethernet Web Server Receiving Client Requests But Not Doing Anything on: January 12, 2013, 10:19:12 pm
It may be your ISP blocks port 80 requests to residential ip addresses. Mine does.

Using a different port may help, like 8080.


That seems fairly plausible. I will try this in the morning smiley
Pages: [1] 2 3