Hi everyone, I really need your help. I'm using a 4052B multiplexer to work with Arduino using the altsoftserial library. Here's the references link to altsoftserial library(AltSoftSerial Library, for an extra serial port).
Based on this table I connect accordingly,
here's my connection
I connect 4052 to Arduino Mega, For the 4052 pin 9 to Digital 6 , Pin 10 to Digital 7 and pin 3 to Digital 48 , pin 13 to Digital 46. Here's my code that I used:
#include <AltSoftSerial.h>
AltSoftSerial altSerial;
void setup() {
Serial.begin(9600);
Serial.println("AltSoftSerial Test Begin");
altSerial.begin(9600);
altSerial.println("Hello World");
}
void loop() {
char c;
if (Serial.available()) {
c = Serial.read();
altSerial.print(c);
}
if (altSerial.available()) {
c = altSerial.read();
Serial.print(c);
}
}
I tried several ways to solve this but I'm still stuck, any suggestion to help me ^^ ? Thank you
You have posted a very long program but you haven't explained what problem you are having or where, in the long program, you think the problem might be.
Thanks Robin2 for replying. Okay let me simplify the problem.
#include <AltSoftSerial.h>
AltSoftSerial altSerial;
void setup() {
Serial.begin(9600);
Serial.println("AltSoftSerial Test Begin");
altSerial.begin(9600);
altSerial.println("Hello World");
}
void loop() {
char c;
if (Serial.available()) {
c = Serial.read();
altSerial.print(c);
}
if (altSerial.available()) {
c = altSerial.read();
Serial.print(c);
}
}
The connection is similiar and I tried this coding. What I see on my serial monitor is just "AltSoftSerial Test Begin" . I'm suppose to see "Hello World" but it isn't appearing could anyone explain to me where I went wrong?
I'm suppose to see "Hello World" but it isn't appearing could anyone explain to me where I went wrong?
Perhaps with the incorrect assumption as to WHERE you are supposed to see "Hello World". You will NOT see it on the serial monitor.
The altSerial instance is talking/listening to the multiplexer. What that is doing is a mystery. Why is should care about "Hello World" is equally a mystery.
First of all this is a combination of hardware and software so the Fritzing is not going to work as a schematic because the pin numbers are unreadable on the chip. Please draw a schematic by hand on a piece of printer paper with a black pen and take a photo of it and post that. Alternately you can choose to simply post a wiring list that identifies the chip pin functions as defined on the datasheet for the 4052 along with their corresponding pin numbers on the left side of the list with their Mega pins on the right.
I connect 4052 to Arduino Mega,
For the 4052 pin 9 (addr:-B) to Digital 6
Pin 7 (Vee) to Digital 7
pin 3 (Com-Y Out/In ) to Digital 48
pin 13 (Com-X Out/In) to Digital 46
:
The MUX is miswired. Read the datasheet. Look at the addressing pin numbers for the 4052.
Also, if your code is reading from the Mega default serial and echoing to the soft serial then the MUX input pins should go to the Mega Tx & Rx
Your addressing lines are miswired (you have no Address-A) and I don't see any code controlling the address pins.
Are the address pins controlled by the AltSoftSerial library ?
Post the wiring list and identify the pin functions for both the 4052 pins AND the Mega pins since your code tells us nothing about the Mega pin functions (there are no comments to that effect ) )
luckystar94:
The connection is similiar and I tried this coding. What I see on my serial monitor is just "AltSoftSerial Test Begin" . I'm suppose to see "Hello World" but it isn't appearing could anyone explain to me where I went wrong?
I think you have a basic misunderstanding about what AltSoftSerial does. It's purpose is to act as a second separate serial port quite unconnected with hardware serial.
I also missed the fact that you are using a Mega. The Mega has 4 hardware serial ports so there should be no need to use any version of SoftwareSerial.
In either case only the first serial port can display stuff on the serial monitor. Any of the other serial ports (Serial1, 2 or 3 OR SoftwareSerial) work with other I/O pins.
To recap:
1- you are using SoftSerial unnecessarily
2- your MUX is miswired (no code to control the address lines)(you have one of the address lines connected to Vee (the neg voltage power supply pin for the chip))
3- your default serial pins Rx & Tx have nothing connected to them
Thanks raschemmel and robin2 for correcting my mistake.
@raschemmel I made a typo in the post. In actual wiring I did wired correctly. Also you wanted a schematic right? Here's the schematic of my connection.
@Robin2 I'm fully aware that there's 4 hardware serial port but I've already used up all thus I would need a softserial or rather altsoftserial library to create another port for my multiplexer to increase up to 16 serial port on Arduino mega. Any advice that can assist me ?
In my coding, what I want achieve is to make the altsoftserial work on Arduino Mega only. I have no other intention. But so far, I couldn't achieve that and I hope someone could explain to me fully why it work on Arduino Uno but not on Arduino Mega. Thank you.
luckystar94:
I've already used up all thus I would need a softserial or rather altsoftserial library to create another port for my multiplexer to increase up to 16 serial port on Arduino mega. Any advice that can assist me ?
I think it would make a lot more sense to connect one of the Hardware serial ports to your multiplexer and use software-serial for something less complex.
Have you got AltSoftSerial to work on your Mega in a short sketch without any other code?
Can you edit that huge picture to reduce its size so it fits the width of a normal screen.
Also you wanted a schematic right? Here's the schematic of my connection.
The point of a schematic is to show pin functions , origin and destination.
there is no point in the schematic you just posted because it tells us nothing. Each pin should have a function name taken from the datasheet(did you read it yet?). That means the address pins should be labeled "A" & "B" (depends on manufacturer) The common pins should be labeled "X IN/OUT" , "y IN/OUT"" etc, etc. etc.
redo your schematic and add the pin names exactly as they appear on the datasheet.
@Robin2 yeah I know it would be better to use the hardware serial port but it's all used up and the library for altsoftserial restrict me to use on certain pins only. I've been using it on Arduino UNO and it function perfectly but I try on Arduino Mega nothing came out and I'm not sure what's the reason I thought I did something wrong so I follow step by step in this websitehttps://www.pjrc.com/teensy/td_libs_AltSoftSerial.html and connect them accordingly. So I'm trying to solve the problem.
@raschemmel Pardon me. I really need your help. Plus I'm very new to coding and even electronic stuff so I'm trying my very best to catch up in this field. Please pardon me . Is this what you required?
Let me know if you need any more information. Thank you.
raschemmel:
EACH PIN SHOULD HAVE A FUNCTION NAME TAKEN FROM THE DATASHEET (DID YOU READ IT YET?).
THAT MEANS THE ADDRESS PINS SHOULD BE LABELED "A" & "B"
THE COMMON PINS SHOULD BE LABELED "X IN/OUT" and "Y IN/OUT " etc, etc. etc.
Post the datasheet you are using or link to the datasheet. The pin names are specific to the manufacturer and I don't know the manufacturer of the chip you are using . Make sure the datasheet you are using matches the part number on the chip. Your chip labels
make sense to you but without the datasheet you are using I can't check them.
Your IC drawing has arrows . The use of arrows is for denoting the direction of the signals. Arrows point toward the ic indicate
(should indicate) inputs. Arrows pointing away from the chip should indicate outputs. You have more outputs than inputs which can only mean you are either missing arrows or they are pointing the wrong way. In addition, you have not identified the function or purpose of the Mega pins you put in that drawing. Obviously, two of them must be address lines and I think two of them must be analog inputs. You drawing doesn't indicate their function in the circuit.
Also , as I mentioned in a previous post, each 4052 manufacturer has a different part number and pin labels but they are all electrically compatible. If the circuit worked and we didn't want to talk about it , it wouldn't matter much which chip you used or which datasheet. In this case we need to know the exact part number on the chip and which datasheet you used to verify that the datasheet you used is the correct one for the chip you are using. We have no information on either because you simple used the part number "4052" which cannot possibly be the complete part number. Every 4052 chip part number has letters in front of and some at the end of the "4052". Please post the complete exact part number and the datasheet.
@Robin2 No.... I've been trying to use this code to try it out on MEGA
#include <AltSoftSerial.h>
AltSoftSerial altSerial;
void setup() {
Serial.begin(9600);
Serial.println("AltSoftSerial Test Begin");
altSerial.begin(9600);
altSerial.println("Hello World");
}
void loop() {
char c;
if (Serial.available()) {
c = Serial.read();
altSerial.print(c);
}
if (altSerial.available()) {
c = altSerial.read();
Serial.print(c);
}
}
If I can't get the result of this code, I wouldn't proceed on to the next step... In addition this is the most simplify code that you can get it to work with Arduino Mega, I've tried to put in other pins but it wouldn't work.... The Only things I can suspect is either I forget to do something important or the pin allocation is wrong. But my instinct tell me that most likely is I allocate the pins wrongly that why it's not working.
and I didn't see any references to analog multiplexers so I have no idea how your code relates to your circuit.
If you could enlighten me that would be great.