Show Posts
Pages: 1 2 [3] 4 5 ... 22
31  Using Arduino / Project Guidance / Re: Arduino caliper on: March 31, 2014, 07:04:13 am
Rather than build a digital caliper with an Arduino, it may be easier to hack one of the cheap digital calipers and use an Arduino to read the calipers. This has been done by a member of these forums. Simply google "interfacing arduino with a digital caliper". How do they work? Google "how do digital calipers work?". - Scotty
32  Using Arduino / Programming Questions / Re: Arduino > USB Host > RAZR Phone on: March 30, 2014, 07:47:12 pm
Thanks alot Paul. That helped a whole bunch.

Here's the code:
Code:
#include <cdcacm.h>
#include <usbhub.h>

#include "pgmstrings.h"

// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif



class ACMAsyncOper :
public CDCAsyncOper
{
public:
  virtual uint8_t OnInit(ACM *pacm);
};

uint8_t ACMAsyncOper::OnInit(ACM *pacm)
{
  uint8_t rcode;
  // Set DTR = 1 RTS=1
  rcode = pacm->SetControlLineState(3);

  if (rcode)
  {
    ErrorMessage<uint8_t>(PSTR("SetControlLineState"), rcode);
    return rcode;
  }

  LINE_CODING lc;
  lc.dwDTERate = 115200;
  lc.bCharFormat = 0;
  lc.bParityType = 0;
  lc.bDataBits = 8;


  rcode = pacm->SetLineCoding(&lc);

  if (rcode)
    ErrorMessage<uint8_t>(PSTR("SetLineCoding"), rcode);

  return rcode;
}

USB     Usb;
//USBHub     Hub(&Usb);
ACMAsyncOper  AsyncOper;
ACM           Acm(&Usb, &AsyncOper);

boolean done = false;
uint8_t rcode;
char mode[] = "AT+CMGF=1\r"; //used to put phone into text mode
int modelen = strlen(mode);
char phone[] = "AT+CMGW=16105551212\n>FROM RAZR\z";
int phonelen = strlen(phone);
char message[] = "From Razr!\r";
int messagelen = strlen(message);

void setup()
{
  Serial.begin( 115200 );
  while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
  Serial.println("Start");

  if (Usb.Init() == -1)
    Serial.println("OSCOKIRQ failed to assert");
  delay( 200 );
}

void loop()
{
  Usb.Task();

  if( Acm.isReady()) {
    //uint8_t rcode;

    /* sending to the phone */
    if (done==false){//if true, prevents multiple messages from being sent

      Mode_Setup();
      delay(500);
      Read_Function();
      delay(500);
      Enter_Number();
      delay(1000);
      //Read_Function();
      //delay(500);
      //Send_Message();
      //delay(500);
      //Read_Function();
      //delay(500); 
    }
    if (rcode)
      ErrorMessage<uint8_t>(PSTR("SndData"), rcode);

    //Serial.println("            DATA SENT");
    done = true;
  }
  delay(50);

}//if( Usb.getUsbTaskState() == USB_STATE_RUNNING..

int Mode_Setup(){
  for (int i = 0; i < modelen; i++){
    uint8_t data = mode[i];
    rcode = Acm.SndData(1, &data);
  }
  Serial.println("                         Mode Setup Complete");
}

int Enter_Number(){
  for (int i = 0; i < phonelen; i++){
    uint8_t data = phone[i];
    rcode = Acm.SndData(1, &data);
    delay(50);
  }
  Serial.println("                         Enter Number Complete");
}

int Send_Message(){
  for (int i = 0; i < messagelen; i++){
    uint8_t data = message[i];
    rcode = Acm.SndData(1, &data);
  }
  Serial.println("                         Send Message Complete");
}

int Read_Function(){
  /* reading the phone */
  /* buffer size must be greater or equal to max.packet size */
  /* it it set to 64 (largest possible max.packet size) here, can be tuned down
   for particular endpoint */
  Serial.println ("In Read Function");
  uint8_t  buf[64];
  uint16_t rcvd = 64;
  rcode = Acm.RcvData(&rcvd, buf);
  if (rcode && rcode != hrNAK)
    ErrorMessage<uint8_t>(PSTR("Ret"), rcode);

  if( rcvd ) { //more than zero bytes received
    for(uint16_t i=0; i < rcvd; i++ ) {
      Serial.print((char)buf[i]); //printing on the screen
    }
  }
  delay(10);
}

I can now send commands to the phone. However, I've run into a little snag. The command I need to use is:
AT+CMGW="phonenumber"\n
 > Type your message here.\z
Which sends a single SMS message.

(The message being embedded in char phone[] in the sketch. Now that I think of it, it makes sense that a number shouldn't be dialed and then the message typed in. The number should be dialed after the message is typed.)

It won't compile because of the \z. The error message is 'unknown escape sequence \z. I've tried adding the decimal value of 26, i.e. char phone[] = "AT+CMGW=16105551212\n>message"+26; in lieu of \z but I get a different error message about the size of 'phone'.

I have been successful in calling another phone using ATD+12125551212; just to ensure I can dial out from the RAZR.

The following is displayed in the serial monitor when the sketch is executed:

Start
0705890300100A0705010200200007058202002000                         Mode Setup Complete
In Read Function
AT+CMGF=1

OK
                         Enter Number Complete


Can anyone suggest a remedy?
Thanks - Scotty
33  Using Arduino / Programming Questions / Re: Arduino > USB Host > RAZR Phone on: March 30, 2014, 07:06:01 pm
Thanks alot Paul. That helped
34  Using Arduino / Programming Questions / Arduino > USB Host > RAZR Phone on: March 28, 2014, 02:09:05 pm
Hello Guys. I'm working on  a project to notify me, via text, of certain conditions at my home. I have been able to send text to the RAZR via the Aduino IDE Serial Monitor, using the sketch below. Of course, I would like the Arduino to send the messages autonomously. Another fellow has been working on the same project and has asked the same question to the author of the sketch. His response was to 'Just replace strings that I send with strings you need to send.' I assume this in reference to the line of code: rcode = Acm.SndData(1, &data);. I've tried different approaches such as filling the variable 'data' with characters, a sting, numeric values, etc. to no avail. Most of the time, the error references some code in the cdcacm library. The error is as follows:

acm_terminal.ino: In function 'void loop()':
acm_terminal:71: error: invalid conversion from 'const char*' to 'uint8_t*'
acm_terminal:71: error: initializing argument 2 of 'uint8_t ACM::SndData(uint16_t, uint8_t*)'

It seems to me it should be relatively easy to have the Arduino send text as is done via the serial monitor. Within an Arduino sketch, is it possible to emulate sending text entered via the serial monitor?

Thanks - Scotty


Code:
#include <cdcacm.h>
#include <usbhub.h>

#include "pgmstrings.h"

// Satisfy IDE, which only needs to see the include statment in the ino.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif

class ACMAsyncOper : public CDCAsyncOper
{
public:
    virtual uint8_t OnInit(ACM *pacm);
};

uint8_t ACMAsyncOper::OnInit(ACM *pacm)
{
    uint8_t rcode;
    // Set DTR = 1 RTS=1
    rcode = pacm->SetControlLineState(3);

    if (rcode)
    {
        ErrorMessage<uint8_t>(PSTR("SetControlLineState"), rcode);
        return rcode;
    }

    LINE_CODING lc;
    lc.dwDTERate = 115200;
    lc.bCharFormat = 0;
    lc.bParityType = 0;
    lc.bDataBits = 8;

    rcode = pacm->SetLineCoding(&lc);

    if (rcode)
        ErrorMessage<uint8_t>(PSTR("SetLineCoding"), rcode);

    return rcode;
}

USB     Usb;
//USBHub     Hub(&Usb);
ACMAsyncOper  AsyncOper;
ACM           Acm(&Usb, &AsyncOper);

void setup()
{
  Serial.begin( 115200 );
  while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
  Serial.println("Start");

  if (Usb.Init() == -1)
      Serial.println("OSCOKIRQ failed to assert");

  delay( 200 );
}

void loop()
{
    Usb.Task();

    if( Acm.isReady()) {
       uint8_t rcode;

       /* reading the keyboard */
       if(Serial.available()) {
         uint8_t data= Serial.read();
         /* sending to the phone */
         rcode = Acm.SndData(1, &data);
         if (rcode)
            ErrorMessage<uint8_t>(PSTR("SndData"), rcode);
       }//if(Serial.available()...

       delay(50);

        /* reading the phone */
        /* buffer size must be greater or equal to max.packet size */
        /* it it set to 64 (largest possible max.packet size) here, can be tuned down
        for particular endpoint */
        uint8_t  buf[64];
        uint16_t rcvd = 64;
        rcode = Acm.RcvData(&rcvd, buf);
         if (rcode && rcode != hrNAK)
            ErrorMessage<uint8_t>(PSTR("Ret"), rcode);

            if( rcvd ) { //more than zero bytes received
              for(uint16_t i=0; i < rcvd; i++ ) {
                Serial.print((char)buf[i]); //printing on the screen
              }
            }
        delay(10);
    }//if( Usb.getUsbTaskState() == USB_STATE_RUNNING..
}
35  Using Arduino / Project Guidance / Re: Automated Chicken Feeder - Noob needs help on: March 26, 2014, 07:02:32 am
Quote
turning the motor on for a set time and reversing it the same amount of time to open close the valve?

That method might work sometime but I doubt it would work correctly consistently. The problem with the method is, depending on the load, that there is no way to determine the length of time it will take for the door to open or close. Besides that, the time it will take for the door to open or close will also greatly depend of the charge state of the battery. You cannot recharge a "just those ones you buy from the supermarket" battery.

I think you need to rethink this design. Your current one is just too flawed.

- Scotty
36  Using Arduino / Project Guidance / Re: Automated Chicken Feeder - Noob needs help on: March 25, 2014, 06:56:10 am
Welcome to the forums.
At 12v, under no load, that motor would make 1.2 revolutions in 2 seconds. Rather than controlling the length of time to the open or closed positions, I think a better approach would be to sense the open and closed positions and operate the motor until the desired position is reached. What power supply is used for powering the motor? - Scotty
37  Using Arduino / Programming Questions / Re: HC SR-04 and servo problem. on: March 24, 2014, 06:44:40 am
Welcome to these forums. Please read and follow the instructions contained in the sticky post, the first post on this forum's opening page. - Scotty
38  Using Arduino / Project Guidance / Re: Wiring specifics on: March 21, 2014, 10:51:20 am
Perhaps a single pole double throw wall switch and an Arduino controlled SPDT latching relay, following the wiring of Peter's first link. - Scotty
39  Using Arduino / Project Guidance / Re: Wiring specifics on: March 21, 2014, 06:07:01 am
I'm not clear on the switch. Are you referring to a switch such as a common light switch as might be might be mounted in a wall to control the mains directly or a small, low voltage switch that you might find at Radio Shack that you can attach to an Arduino? - Scotty
40  Using Arduino / Project Guidance / Re: Wiring specifics on: March 20, 2014, 06:49:04 am
Does this circuitry involve AC mains voltage? - Scotty
41  Using Arduino / General Electronics / Re: detecting when power is on, to a record player. on: March 17, 2014, 06:54:29 am
I think Peter meant that his suggestion wouldn't be intrusive to your player, not your domain. I agree with his suggestion. A very inexpensive, simple device and two wires; about as easy and simple as it gets. - Scotty
42  Using Arduino / Motors, Mechanics, and Power / Re: Stepper Motor Voltage Supply on: March 12, 2014, 06:59:11 am
Quote
Won't different manufacturers have diff configurations, pinouts and torque ratings.

Yes. Go browsing on ebay. You can get an idea of what would suit your project just by looking at the images shown in the posts of the items. Most likely the pinouts will be as simple as you can get, negative and positive. Torque shouldn't be much of a problem if the vertical load is supported by a bearing. - Scotty
43  Using Arduino / Motors, Mechanics, and Power / Re: Stepper Motor Voltage Supply on: March 11, 2014, 07:53:20 am
The device below (an automotive window regulator) may be a good solution. Inexpensive, readily available, powerful, and holds position with no power applied. I incorporated it in a solar panel tracker I was working on. I don't plan to try to track the sun's zenith since it wouldn't need constant adjustment and could be done, in my case, manually. The motor draws about 9 amps at locked rotor. I used a relay driver board to apply power. - Scotty


44  Using Arduino / Motors, Mechanics, and Power / Re: Attempting to make a computer controller Power Wheels toy, but new to electronic on: March 04, 2014, 07:53:06 am
Sounds like fun and driving the motors is a feasible project for a beginner. Besides a motor driver, something like this could be used to control the motors forward and reverse but you wouldn't have speed control. Do you plan to have any input devices for control? What about steering? - Scotty
45  Using Arduino / Motors, Mechanics, and Power / Re: How to control speed of motorized pinwheel using a potentiometer on: March 04, 2014, 07:36:28 am
Go here and read, particularly #6. - Scotty
Pages: 1 2 [3] 4 5 ... 22