Help to configure my codes: (BLDC motor is fluctuating)
hi, mods, before move topic of mine, please check first. i'm posting on programming section because issue here little bit of programming.
my codes here works 95% smoothly. please check out:
as indicated in todo:
bldc motor fluctuating, because of wifi codes. me configure codes? i'm new millis() <-- that's solution.
additional: mean in fluctuating, when cc3000 shield has ip address , ready penetrated telnet (lol), motor turning in every direction every 2 seconds? not sure. produces beeps continuously. anyway, developed c# program telnet-ting arduino via wifi, , when connect arduino , starts pressing 'w' or 's', motor runs smoothly.
thanks!
(i'm posting code in reply, long post)
my codes here works 95% smoothly. please check out:
as indicated in todo:
bldc motor fluctuating, because of wifi codes. me configure codes? i'm new millis() <-- that's solution.
additional: mean in fluctuating, when cc3000 shield has ip address , ready penetrated telnet (lol), motor turning in every direction every 2 seconds? not sure. produces beeps continuously. anyway, developed c# program telnet-ting arduino via wifi, , when connect arduino , starts pressing 'w' or 's', motor runs smoothly.
thanks!
(i'm posting code in reply, long post)
code: [select]
//--- code controls bldc using cc3000 wifi shield, esc, arduino, , telnet program
//--- use putty or developed c# program.
//--- hold 'w' incrementing speed of motor, 's' decrease or reverse.
//--- do: motor fluctuating, because of wifi codes.
/***************************************************
* adafruit cc3000 breakout/shield tcp chat server
* simple chat server allows clients connect
* telnet , exchange messages. sent one
* client written out connected clients.
* see cc3000 tutorial on adafruit's learning system
* more information on setting , using the
* cc3000:
* http://learn.adafruit.com/adafruit-cc3000-wifi
* requirements:
* sketch requires adafruit cc3000 library. can
* download library from:
* https://github.com/adafruit/adafruit_cc3000_library
* information on installing libraries in arduino ide
* see page:
* http://arduino.cc/en/guide/libraries
* usage:
* update ssid and, if necessary, cc3000 hardware pin
* information below, run sketch , check the
* output of serial port. after connecting the
* wireless network sketch output
* ip address of server , start listening for
* connections. once listening connections, connect
* server computer using telnet client
* on port 23.
* example on linux or mac osx, if cc3000 has an
* ip address 192.168.1.100 execute in command
* window:
* telnet 192.168.1.100 23
* connect multiple clients , notice whatever 1 client
* sends echoed other clients. press ctrl-] and
* type quit @ prompt close telnet session.
* on windows you'll need download telnet client. putty
* good, free gui client:
* http://www.chiark.greenend.org.uk/~sgtatham/putty/
* license:
* example copyright (c) 2013 tony dicola (tony@tonydicola.com)
* , released under open source mit license. see details at:
* http://opensource.org/licenses/mit
* code adapted adafruit cc3000 library example
* code has following license:
* designed work adafruit wifi products:
* ----> https://www.adafruit.com/products/1469
* adafruit invests time , resources providing open source code,
* please support adafruit , open-source hardware purchasing
* products adafruit!
* written limor fried & kevin townsend adafruit industries.
* bsd license, text above must included in redistribution.
****************************************************/
#include <servo.h> //notice how can use standard servo library!
//====== adafruit wifi codes
#include <adafruit_cc3000.h>
#include <string.h>
#include <spi.h>
#include "utility/debug.h"
#include "utility/socket.h"
// these interrupt , control pins
#define adafruit_cc3000_irq 3 // must interrupt pin!
// these can 2 pins
#define adafruit_cc3000_vbat 5
#define adafruit_cc3000_cs 10
// use hardware spi remaining pins
// on uno, sck = 13, miso = 12, , mosi = 11
adafruit_cc3000 cc3000 = adafruit_cc3000(adafruit_cc3000_cs, adafruit_cc3000_irq, adafruit_cc3000_vbat,
spi_clock_divider); // can change clock speed
#define wlan_ssid "marshmallows" // cannot longer 32 characters!
#define wlan_pass "yanabels82190"
// security can wlan_sec_unsec, wlan_sec_wep, wlan_sec_wpa or wlan_sec_wpa2
#define wlan_security wlan_sec_wpa2
#define listen_port 23 // tcp port listen on connections.
adafruit_cc3000_server chatserver(listen_port);
string cmd;
#define max_cmd_length 25
//============== end of adafruit wifi codes ==============//
//============== bldc+esc codes ty zoomkat ==============//
string readstring;
servo myservo;
int pos=1500; //~neutral value continous rotation servo
//int pos=90;
//============== end of bldc+esc codes =========//
void setup(void)
{
serial.begin(115200);
serial.println(f("hello, cc3000!\n"));
serial.print("free ram: ");
serial.println(getfreeram(), dec);
/* initialise module */
serial.println(f("\ninitializing..."));
if (!cc3000.begin())
{
serial.println(f("couldn't begin()! check wiring?"));
while(1);
}
if (!cc3000.connecttoap(wlan_ssid, wlan_pass, wlan_security)) {
serial.println(f("failed!"));
while(1);
}
serial.println(f("connected!"));
serial.println(f("request dhcp"));
while (!cc3000.checkdhcp())
{
delay(100); // todo: insert dhcp timeout!
}
/* display ip address dns, gateway, etc. */
while (! displayconnectiondetails()) {
delay(1000);
}
/*********************************************************/
/* can safely remove save flash memory! */
/*********************************************************/
serial.println(f("\r\nnote: sketch may cause problems other sketches"));
serial.println(f("since .disconnect() function never called, the"));
serial.println(f("ap may refuse connection requests cc3000 until a"));
serial.println(f("timeout period passes. normal behaviour since"));
serial.println(f("there isn't obvious moment disconnect server.\r\n"));
// start listening connections
chatserver.begin();
serial.println(f("listening connections..."));
//=========== bldc + esc config ==============//
myservo.attach(9, 400, 2600); //servo control pin, , range if desired
//=========== end of bldc + esc config =======//
}
void loop(void)
{
// try client connected.
adafruit_cc3000_clientref client = chatserver.available();
if (client) {
client.flush();
// check if there data available read.
if (client.available() > 0) {
// read byte , write clients.
char thischar = client.read();
if (thischar == '\n')
{
serial.println(cmd);
char cmdarray[1024];
cmd.tochararray(cmdarray,cmd.length()+1);
if(strcmp(cmdarray,"w")==0)
{
serial.println("xxx - arduino arduino serial monitor"); // whatever want
// chatserver.println("equal - xxx arduino server");
// chatserver.println(cmdarray);
// esc+bldc
(pos=pos+1);
}
if(strcmp(cmdarray,"s")==0)
{
serial.println("s");
// chatserver.println("ok got not xxx arduino server");
// chatserver.println(cmdarray);
// esc + bldc
(pos=pos-1); //use larger numbers larger increments
if(pos<0) (pos=0); //prevent negative number
}
if(pos >= 400) //determine servo write method
{
serial.println(pos);
myservo.writemicroseconds(pos);
}
else
{
serial.println(pos);
myservo.write(pos);
}
// end of bldc+esc codes
cmd = "";
}
else
{
cmd += thischar;
}
}
}
}
//=========== not mind codes below.... default adafruit wifi codes ================//
/**************************************************************************/
/*!
@brief tries read ip address , other connection details
*/
/**************************************************************************/
bool displayconnectiondetails(void)
{
uint32_t ipaddress, netmask, gateway, dhcpserv, dnsserv;
if(!cc3000.getipaddress(&ipaddress, &netmask, &gateway, &dhcpserv, &dnsserv))
{
serial.println(f("unable retrieve ip address!\r\n"));
return false;
}
else
{
serial.print(f("\nip addr: "));
cc3000.printipdotsrev(ipaddress);
serial.print(f("\nnetmask: "));
cc3000.printipdotsrev(netmask);
serial.print(f("\ngateway: "));
cc3000.printipdotsrev(gateway);
serial.print(f("\ndhcpsrv: "));
cc3000.printipdotsrev(dhcpserv);
serial.print(f("\ndnsserv: "));
cc3000.printipdotsrev(dnsserv);
serial.println();
return true;
}
}
Arduino Forum > Using Arduino > Project Guidance > Help to configure my codes: (BLDC motor is fluctuating)
arduino
Comments
Post a Comment