Notifications
Clear all

[Sticky] Components & Programming

100 Posts
18 Users
11 Likes
27.5 K Views
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2519
 

@alanl 

Check out < https://quadmeup.com/arduino-esp32-and-3-hardware-serial-ports/>

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6939
 

@alanl Try printing the ch value returned by readChannel

For future reference, read the help on the right above recent posts to learn how to show code, and also to learn how to start your own topic rather than hijacking someone elses.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
AlanL
(@alanl)
Member
Joined: 3 years ago
Posts: 34
 

@will page not found on your link.

Alan


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2519
 

@alanl 

Sorry about that ...

https://quadmeup.com/arduino-esp32-and-3-hardware-serial-ports/

Anything seems possible when you don't know what you're talking about.


   
Ron reacted
ReplyQuote
AlanL
(@alanl)
Member
Joined: 3 years ago
Posts: 34
 

Will, same results as my original code. Channel values are all Zero.

The code:

#include <IBusBM.h>
#include <HardwareSerial.h>

HardwareSerial MySerial(1);
IBusBM IBus; // IBus object

// Possible PWM GPIO pins on the ESP32: 0(used by on-board button),2,4,5(used by on-board LED),12-19,21-23,25-27,32-33
//#define RX2 16
//#define TX2 17

// Read the number of a given channel and convert to the range provided.
// If the channel is off, return the default value
int readChannel(byte channelInput, int minLimit, int maxLimit, int defaultValue) {
uint16_t ch = IBus.readChannel(channelInput);
if (ch < 100) return defaultValue;
return map(ch, 1000, 2000, minLimit, maxLimit);
}

// Read the channel and return a boolean value
bool readSwitch(byte channelInput, bool defaultValue) {
int intDefaultValue = (defaultValue) ? 100 : 0;
int ch = readChannel(channelInput, 0, 100, intDefaultValue);
return (ch > 50);
}

void setup() {

// Start serial monitor
Serial.begin(115200);
MySerial.begin(9600, SERIAL_8N1, 16, 17);
IBus.begin(MySerial);

//IBus.begin(Serial2, 1); // iBUS object connected to serial2 RX2 pin using timer 1
}

void loop() {

// Cycle through first 5 channels and determine values
// Print values to serial monitor
// Note IBusBM library labels channels starting with "0"

for (byte i = 0; i < 5; i++) {
int value = readChannel(i, -100, 100, 0);
Serial.print("Ch");
Serial.print(i + 1);
Serial.print(": ");
Serial.print(value);
Serial.print(" | ");
}

// Print channel 6 (switch) boolean value
Serial.print("Ch6: ");
Serial.print(readSwitch(5, false));
Serial.println();

delay(10);
}

 

The above code is based on Bill's "Build an ESP32CAM Robot Car"

Switching back to the Mega version proves the iA6B is working correctly.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6939
 

@alanl First you should start your own topic. Second is learn how to reply, third is learn how to post code and fourth is properly format it using the normal conventions re indentations (2) and brace placement and matching. When done right, folding works properly.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@catch)
Not anymore. You’ll are just too rude
Joined: 1 year ago
Posts: 9
 

Posted by: @dronebot-workshop

Welcome to the Components & Programming section.  In this section you can post about topics such as:

  • Arduino hardware and sketches - if you're having difficulty with an Arduino-based design or understanding how to program please post your questions here.
  • Raspberry Pi related inquiries - same as with the Arduino, your questions and comments are welcome here.
  • Other microcontrollers and microcomputers - we aren't just focused on the Arduino and Raspberry Pi! Post any comments or questions about your device here.
  • Understanding electronics - if you're having problems understanding any aspect of electronics ask your questions here.
  • Sensors and Displays - Anything you can connect to your microcontroller or microcomputer qualifies, so if you have any problems using I/O devices let us know.

In short, this is a pretty general section and if in doubt it's probably where you want to post. There are, however, a few exceptions:

  • If you are building a project and are having problems or would like to show it off there is a section for that.
  • There is also a separate forum for robotics-related questions and projects.

Thanks!

Bill

 

I'm having a hard time even putting up a post! I found this but I'm pretty sure it is NOT the correct spot.

I'm totally frustrated at attempting to get help with a gate open/close project. I have no way to post on the forms. There is nothing I see to make a welcome it's me post. Arrrrg! I get these forums are a bit different but, again, no way to post on those forums. Any help would be appreciated. Oh, I will leave a quote though.

Never argue with a fool. Onlookers often cannot tell the difference. M. Twain

 

Please remove me from the membership and delete my profile. Thank you


   
ReplyQuote
(@catch)
Not anymore. You’ll are just too rude
Joined: 1 year ago
Posts: 9
 

I found where to post, finally.

I'm having problems. I'm pretty sure most of the problem is my disability, not being able to retain information. I could use all the help offered. I am attempting to build an automatic gate opener/closer that operates from a wireless relay activated by a key fob. I have an Arduino Uno for the processer, a MD20A Cytron motor controller, 12vDC lawnmower battery, and a mini buck converter to feed both off the battery. I have a harbor freight battery tender to keep the battery charged. the gate opener was a mighty mule mm372W until the main board died. a new one is way beyond my price range at $170.00. 

  I've been listening/watching the DroneBot WorkShop for a couple of years and so I thought I'd give it a shot. probably not the best move for me but I like to build. I have a sketch. I's a nightmare abortion and I'm ashamed to post it but have no choice but to post it and try to get help. feel free to correct it or even rewrite it. here ya go;

 

#include"arduino.h"
#include"CytronMotorDriver.h"
#include"wiring_private.h"
 // Define switch connections
const byte buttonPin = 2;

 CytronMD Motor-toggle.ino
 CytronMD Motor Toggle

 // Configure the motor driver.

 CytronMD motor(PWM_DIR, 3, 4);  // PWM = Pin 3, DIR = Pin 4.
 // Boolean to represent toggle state
volatilebool toggleState = true;

voidcheckSwitch(){
  // Check status of switch
  // Toggle motor if button pressed
if(digitalRead(buttonPin) == LOW)
{
    // Switch was pressed
    // Slight delay to debounce
delay(200);
    // Change state of toggle
    toggleState = !toggleState;
    // Indicate state on LED
    cytronMD motor(PWM_DIR, toggleState);
}
}
voidsetup(){
   // Set LED pin as output
pinMode(PWM_DIR, OUTPUT);
  // Set switch pin as INPUT with pullup
pinMode(buttonPin, INPUT_PULLUP);
}
voidloop(){
  // Check switch
checkSwitch();
}
 // The setup routine runs once when you press reset.
voidsetup()

{
motor.setspeed(64);   //Run forward at 25% speed
delay(100);
motor.setSpeed(128);  // Run forward at 50% speed.
delay(100);
motor.setSpeed(255);  // Run forward at full speed.
delay(7000);
motor.setSpeed(0);    // Stop.
delay(15000);
motor.setspeed(-64);   // Run motor backward at 25%
delay(100);
motor.setSpeed(-128);  // Run backward at 50% speed.
delay(100);
motor.setSpeed(-255);  // Run backward at full speed.
delay(7000);
motor.setSpeed(0);    // Stop.
}

 // The loop routine runs over and over again forever.
voidloop()
delay(10000)
 
more problems than I can count. HELP!

Please remove me from the membership and delete my profile. Thank you


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2519
 

@catch 

First, you should start a new thread in a suitable section of the forum with a title that describes your situation. That way you'll draw more attention and help that you will get piggy-backing on somebody else's thread.

Second, please read the instructions on how to post code and then re-post your sketch properly. I tried to copy and paste what you have above and it's totally unusable. The type merges with the subroutine name and you appear to have multiple setup() and loop() modules.

We'd like to help you but you have to meet us half way 🙂

Anything seems possible when you don't know what you're talking about.


   
Ron reacted
ReplyQuote
(@catch)
Not anymore. You’ll are just too rude
Joined: 1 year ago
Posts: 9
 

Yep. I figured I had done it wrong. Again sorry about that. I dont know how to erase it or i would. I’m pretty sure this kinda stuff is now beyond me anyway. Too much loss up stairs now. This is

Please remove me from the membership and delete my profile. Thank you


   
ReplyQuote
(@catch)
Not anymore. You’ll are just too rude
Joined: 1 year ago
Posts: 9
 

@will

#include"arduino.h"
#include"CytronMotorDriver.h"
#include"wiring_private.h"
 // Define switch connections
const byte buttonPin = 2;

 

 CytronMD Motor-toggle.ino
 CytronMD Motor Toggle

 

 // Configure the motor driver.

 

 CytronMD motor(PWM_DIR, 34);  // PWM = Pin 3, DIR = Pin 4.
 // Boolean to represent toggle state
volatilebool toggleState = true;

 

voidcheckSwitch(){
  // Check status of switch
  // Toggle motor if button pressed
if(digitalRead(buttonPin) == LOW)
{
    // Switch was pressed
    // Slight delay to debounce
delay(200);
    // Change state of toggle
    toggleState = !toggleState;
    // Indicate state on LED
    cytronMD motor(PWM_DIR, toggleState);
}
}
voidsetup(){
   // Set LED pin as output
pinMode(PWM_DIR, OUTPUT);
  // Set switch pin as INPUT with pullup
pinMode(buttonPin, INPUT_PULLUP);
}
voidloop(){
  // Check switch
checkSwitch();
}
 // The setup routine runs once when you press reset.
voidsetup()

 

{
motor.setspeed(64);   //Run forward at 25% speed
delay(100);
motor.setSpeed(128);  // Run forward at 50% speed.
delay(100);
motor.setSpeed(255);  // Run forward at full speed.
delay(7000);
motor.setSpeed(0);    // Stop.
delay(15000);
motor.setspeed(-64);   // Run motor backward at 25%
delay(100);
motor.setSpeed(-128);  // Run backward at 50% speed.
delay(100);
motor.setSpeed(-255);  // Run backward at full speed.
delay(7000);
motor.setSpeed(0);    // Stop.
}

 

 // The loop routine runs over and over again forever.
voidloop()
delay(10000)
 
more problems than I can count. HELP!

#include"arduino.h"
#include"CytronMotorDriver.h"
#include"wiring_private.h"
 // Define switch connections
const byte buttonPin = 2;
 CytronMD Motor-toggle.ino
 CytronMD Motor Toggle
 // Configure the motor driver.
 CytronMD motor(PWM_DIR, 3, 4);  // PWM = Pin 3, DIR = Pin 4.
 // Boolean to represent toggle state
volatilebool toggleState = true;
voidcheckSwitch(){
  // Check status of switch
  // Toggle motor if button pressed
if(digitalRead(buttonPin) == LOW)
{
    // Switch was pressed
    // Slight delay to debounce
delay(200);
    // Change state of toggle
    toggleState = !toggleState;
    // Indicate state on LED
    cytronMD motor(PWM_DIR, toggleState);
}
}
voidsetup(){
   // Set LED pin as output
pinMode(PWM_DIR, OUTPUT);
  // Set switch pin as INPUT with pullup
pinMode(buttonPin, INPUT_PULLUP);
}
voidloop(){
  // Check switch
checkSwitch();
}
 // The setup routine runs once when you press reset.
voidsetup()
{
motor.setspeed(64);   //Run forward at 25% speed
delay(100);
motor.setSpeed(128);  // Run forward at 50% speed.
delay(100);
motor.setSpeed(255);  // Run forward at full speed.
delay(7000);
motor.setSpeed(0);    // Stop.
delay(15000);
motor.setspeed(-64);   // Run motor backward at 25%
delay(100);
motor.setSpeed(-128);  // Run backward at 50% speed.
delay(100);
motor.setSpeed(-255);  // Run backward at full speed.
delay(7000);
motor.setSpeed(0);    // Stop.
}
 // The loop routine runs over and over again forever.
voidloop()
delay(10000)
 
more problems than I can count. HELP!

Please remove me from the membership and delete my profile. Thank you


   
ReplyQuote
(@catch)
Not anymore. You’ll are just too rude
Joined: 1 year ago
Posts: 9
 

@bill I really hope I got it correct this time. did ya know this is my first comfusef? yep! never had one before my kids dragged me into the 20th century

Please remove me from the membership and delete my profile. Thank you


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6939
 

@catch Low hanging fruit first, you have 2 setups and 2 loops. Only one of each is allowed. Some words are run together like voidsetup which should be void setup. Check the first 10 lines there are multiple problems.

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
(@catch)
Not anymore. You’ll are just too rude
Joined: 1 year ago
Posts: 9
 

@zander  ya, i know there are errors in it. I don't learn like other folks. it takes me a lot longer to learn anything cause everything is backwards. i think I'ma leave this stuff to folks that can read. it was nice meetin all of you

Please remove me from the membership and delete my profile. Thank you


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2519
 

Anything seems possible when you don't know what you're talking about.


   
ReplyQuote
Page 6 / 7